Browse Source

Some minor improvements.

pull/17894/head
maliming 3 years ago
parent
commit
aa1d939200
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 28
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs
  2. 7
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs

28
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<IReadOnlyList<BundleFile>> GetBundleFilesAsync(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) protected virtual async Task<IReadOnlyList<BundleFile>> GetBundleFilesAsync(BundleConfigurationCollection bundles, string bundleName, IBundler bundler)
{ {
var result = new List<BundleFile>(); var files = new List<BundleFile>();
var contributors = GetContributors(bundles, bundleName); var contributors = GetContributors(bundles, bundleName);
var bundleFiles = RequestResources.TryAdd(await GetBundleFilesAsync(contributors)); var bundleFiles = RequestResources.TryAdd(await GetBundleFilesAsync(contributors));
var dynamicResources = RequestResources.TryAdd(await GetDynamicResourcesAsync(contributors)); var dynamicResources = RequestResources.TryAdd(await GetDynamicResourcesAsync(contributors));
@ -82,31 +81,28 @@ public class BundleManager : IBundleManager, ITransientDependency
var localBundleFiles = new List<string>(); var localBundleFiles = new List<string>();
foreach (var bundleFile in bundleFiles) 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); files.AddRange(AddToBundleCache(bundleName, bundler, localBundleFiles).Files);
result.AddRange(cacheItem.Files);
localBundleFiles.Clear(); localBundleFiles.Clear();
} }
result.Add(bundleFile); files.Add(bundleFile);
}
else
{
localBundleFiles.Add(bundleFile.File);
} }
} }
if (localBundleFiles.Any()) if (localBundleFiles.Count != 0)
{ {
var cacheItem = AddToBundleCache(bundleName, bundler, localBundleFiles); files.AddRange(AddToBundleCache(bundleName, bundler, localBundleFiles).Files);
result.AddRange(cacheItem.Files);
localBundleFiles.Clear();
} }
return result.Union(dynamicResources).ToImmutableList(); return files.Union(dynamicResources).ToImmutableList();
} }
private BundleCacheItem AddToBundleCache(string bundleName, IBundler bundler, List<string> bundleFiles) private BundleCacheItem AddToBundleCache(string bundleName, IBundler bundler, List<string> bundleFiles)

7
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))) var deferText = (defer || Options.DeferScriptsByDefault || Options.DeferScripts.Any(x => file.File.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
? "defer" ? "defer "
: string.Empty; : string.Empty;
var nonceText = (viewContext.HttpContext.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceString && !string.IsNullOrEmpty(nonceString)) var nonceText = (viewContext.HttpContext.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceString && !string.IsNullOrEmpty(nonceString))
? $"nonce=\"{nonceString}\"" ? $"nonce=\"{nonceString}\" "
: string.Empty; : string.Empty;
var src = file.IsCdn ? file.File : viewContext.GetUrlHelper().Content((file.File + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); var src = file.IsCdn ? file.File : viewContext.GetUrlHelper().Content((file.File + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~'));
output.Content.AppendHtml($"<script {deferText} {nonceText} src=\"{src}\"></script>{Environment.NewLine}"); output.Content.AppendHtml($"<script {deferText}{nonceText}src=\"{src}\"></script>{Environment.NewLine}");
} }
} }

Loading…
Cancel
Save