From aa1d939200f79993f23f17f148e15e22e1c8ae6b Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 17 Oct 2023 20:12:06 +0800 Subject: [PATCH] Some minor improvements. --- .../Mvc/UI/Bundling/BundleManager.cs | 28 ++++++++----------- .../TagHelpers/AbpTagHelperScriptService.cs | 7 ++--- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs index 5a46e1ff5a..fb7b3cd489 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs @@ -67,10 +67,9 @@ public class BundleManager : IBundleManager, ITransientDependency protected virtual async Task> GetBundleFilesAsync(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) { - var result = new List(); + var files = new List(); var contributors = GetContributors(bundles, bundleName); - var bundleFiles = RequestResources.TryAdd(await GetBundleFilesAsync(contributors)); var dynamicResources = RequestResources.TryAdd(await GetDynamicResourcesAsync(contributors)); @@ -82,31 +81,28 @@ public class BundleManager : IBundleManager, ITransientDependency var localBundleFiles = new List(); foreach (var bundleFile in bundleFiles) { - if (bundleFile.IsCdn) + if (!bundleFile.IsCdn) + { + localBundleFiles.Add(bundleFile.File); + } + else { - if (localBundleFiles.Any()) + if (localBundleFiles.Count != 0) { - var cacheItem = AddToBundleCache(bundleName, bundler, localBundleFiles); - result.AddRange(cacheItem.Files); + files.AddRange(AddToBundleCache(bundleName, bundler, localBundleFiles).Files); localBundleFiles.Clear(); } - result.Add(bundleFile); - } - else - { - localBundleFiles.Add(bundleFile.File); + files.Add(bundleFile); } } - if (localBundleFiles.Any()) + if (localBundleFiles.Count != 0) { - var cacheItem = AddToBundleCache(bundleName, bundler, localBundleFiles); - result.AddRange(cacheItem.Files); - localBundleFiles.Clear(); + files.AddRange(AddToBundleCache(bundleName, bundler, localBundleFiles).Files); } - return result.Union(dynamicResources).ToImmutableList(); + return files.Union(dynamicResources).ToImmutableList(); } private BundleCacheItem AddToBundleCache(string bundleName, IBundler bundler, List bundleFiles) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs index ec6ed2c99c..3ff8e05552 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs @@ -48,13 +48,12 @@ public class AbpTagHelperScriptService : AbpTagHelperResourceService }; var deferText = (defer || Options.DeferScriptsByDefault || Options.DeferScripts.Any(x => file.File.StartsWith(x, StringComparison.OrdinalIgnoreCase))) - ? "defer" + ? "defer " : string.Empty; var nonceText = (viewContext.HttpContext.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceString && !string.IsNullOrEmpty(nonceString)) - ? $"nonce=\"{nonceString}\"" + ? $"nonce=\"{nonceString}\" " : string.Empty; - var src = file.IsCdn ? file.File : viewContext.GetUrlHelper().Content((file.File + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); - output.Content.AppendHtml($"{Environment.NewLine}"); + output.Content.AppendHtml($"{Environment.NewLine}"); } }