From 300c05fc2ebd5dcdc6da7a6325b322157ca152e5 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 17 Oct 2023 17:43:27 +0800 Subject: [PATCH 1/5] Add CDN support for bundles. --- .../UI/Bundling/BundleConfigurationContext.cs | 4 +- .../Bundling/BundleConfigurationExtensions.cs | 7 +++ .../BundleContributorCollectionExtensions.cs | 4 ++ .../AspNetCore/Mvc/UI/Bundling/BundleFile.cs | 14 +++++ .../Mvc/UI/Bundling/BundleFileContributor.cs | 14 +++-- .../UI/Bundling/BundleFileListExtensions.cs | 32 +++++++++++ .../Bundling/IBundleConfigurationContext.cs | 2 +- .../Mvc/UI/Bundling/BundleCacheItem.cs | 4 +- .../Mvc/UI/Bundling/BundleManager.cs | 54 +++++++++++++++---- .../Mvc/UI/Bundling/IBundleManager.cs | 4 +- .../TagHelpers/AbpTagHelperResourceService.cs | 34 +++++++----- .../TagHelpers/AbpTagHelperScriptService.cs | 11 ++-- .../TagHelpers/AbpTagHelperStyleService.cs | 16 +++--- .../Mvc/UI/Resources/IWebRequestResources.cs | 3 +- .../Mvc/UI/Resources/WebRequestResources.cs | 7 +-- 15 files changed, 161 insertions(+), 49 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs index b67c8f6d3d..bc4dc14d11 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs @@ -8,7 +8,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public class BundleConfigurationContext : IBundleConfigurationContext { - public List Files { get; } + public List Files { get; } public IFileProvider FileProvider { get; } @@ -18,7 +18,7 @@ public class BundleConfigurationContext : IBundleConfigurationContext public BundleConfigurationContext(IServiceProvider serviceProvider, IFileProvider fileProvider) { - Files = new List(); + Files = new List(); ServiceProvider = serviceProvider; LazyServiceProvider = ServiceProvider.GetRequiredService(); FileProvider = fileProvider; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs index 3ee0fe6cd9..ca628f4d67 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; @@ -10,6 +11,12 @@ public static class BundleConfigurationExtensions return bundleConfiguration; } + public static BundleConfiguration AddCdnFiles(this BundleConfiguration bundleConfiguration, params string[] files) + { + bundleConfiguration.Contributors.AddCdnFiles(files.Select(x => new BundleFile(x, true)).ToArray()); + return bundleConfiguration; + } + public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params IBundleContributor[] contributors) { Check.NotNull(contributors, nameof(contributors)); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs index dc0ac8bfbb..3c0dfdeab8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs @@ -6,4 +6,8 @@ public static class BundleContributorCollectionExtensions { contributors.Add(new BundleFileContributor(files)); } + public static void AddCdnFiles(this BundleContributorCollection contributors, params BundleFile[] files) + { + contributors.Add(new BundleFileContributor(files)); + } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs new file mode 100644 index 0000000000..58427b6c40 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs @@ -0,0 +1,14 @@ +namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; + +public class BundleFile +{ + public string File { get; set; } + + public bool IsCdn { get; set; } + + public BundleFile(string file, bool isCdn = false) + { + File = file; + IsCdn = isCdn; + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs index 7f218e7fbf..5107c006a0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs @@ -1,22 +1,30 @@ using System; using System.Collections.Generic; +using System.Linq; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public class BundleFileContributor : BundleContributor { - public string[] Files { get; } + public List Files { get; } + + public BundleFileContributor(params BundleFile[] files) + { + Files = new List(); + Files.AddRange(files); + } public BundleFileContributor(params string[] files) { - Files = files ?? Array.Empty(); + Files = new List(); + Files.AddRange(files.Select(file => new BundleFile(file))); } public override void ConfigureBundle(BundleConfigurationContext context) { foreach (var file in Files) { - context.Files.AddIfNotContains(x => x.Equals(file, StringComparison.OrdinalIgnoreCase), () => file); + context.Files.AddIfNotContains(x => x.File.Equals(file.File, StringComparison.OrdinalIgnoreCase), () => file); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs new file mode 100644 index 0000000000..b3088b293d --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; + +/// +/// This class is used to compatible with old code. +/// +public static class BundleFileListExtensions +{ + public static void Add(this List bundleFiles, params string[] files) + { + bundleFiles.AddRange(files.Select(file => new BundleFile(file))); + } + + public static void AddRange(this List bundleFiles, params string[] files) + { + bundleFiles.AddRange(files.Select(file => new BundleFile(file))); + } + + public static void AddIfNotContains(this List bundleFiles, params string[] files) + { + foreach (var file in files) + { + if (!bundleFiles.Any(x => x.File.Equals(file, StringComparison.OrdinalIgnoreCase))) + { + bundleFiles.Add(new BundleFile(file)); + } + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleConfigurationContext.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleConfigurationContext.cs index 61d772d638..96df341514 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleConfigurationContext.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleConfigurationContext.cs @@ -5,5 +5,5 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public interface IBundleConfigurationContext : IServiceProviderAccessor { - List Files { get; } + List Files { get; } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleCacheItem.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleCacheItem.cs index 5c3890a852..f6830cbd74 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleCacheItem.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleCacheItem.cs @@ -5,11 +5,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public class BundleCacheItem { - public List Files { get; } + public List Files { get; } public List WatchDisposeHandles { get; } - public BundleCacheItem(List files) + public BundleCacheItem(List files) { Files = files; WatchDisposeHandles = new List(); 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 8291c2c75f..5a46e1ff5a 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 @@ -12,7 +12,6 @@ using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Scripts; using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Styles; using Volo.Abp.AspNetCore.Mvc.UI.Resources; -using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.DependencyInjection; using Volo.Abp.VirtualFileSystem; @@ -56,19 +55,22 @@ public class BundleManager : IBundleManager, ITransientDependency Logger = NullLogger.Instance; } - public virtual async Task> GetStyleBundleFilesAsync(string bundleName) + public virtual async Task> GetStyleBundleFilesAsync(string bundleName) { return await GetBundleFilesAsync(Options.StyleBundles, bundleName, StyleBundler); } - public virtual async Task> GetScriptBundleFilesAsync(string bundleName) + public virtual async Task> GetScriptBundleFilesAsync(string bundleName) { return await GetBundleFilesAsync(Options.ScriptBundles, bundleName, ScriptBundler); } - protected virtual async Task> GetBundleFilesAsync(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) + protected virtual async Task> GetBundleFilesAsync(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) { + var result = new List(); + var contributors = GetContributors(bundles, bundleName); + var bundleFiles = RequestResources.TryAdd(await GetBundleFilesAsync(contributors)); var dynamicResources = RequestResources.TryAdd(await GetDynamicResourcesAsync(contributors)); @@ -77,16 +79,48 @@ public class BundleManager : IBundleManager, ITransientDependency return bundleFiles.Union(dynamicResources).ToImmutableList(); } + var localBundleFiles = new List(); + foreach (var bundleFile in bundleFiles) + { + if (bundleFile.IsCdn) + { + if (localBundleFiles.Any()) + { + var cacheItem = AddToBundleCache(bundleName, bundler, localBundleFiles); + result.AddRange(cacheItem.Files); + localBundleFiles.Clear(); + } + + result.Add(bundleFile); + } + else + { + localBundleFiles.Add(bundleFile.File); + } + } + + if (localBundleFiles.Any()) + { + var cacheItem = AddToBundleCache(bundleName, bundler, localBundleFiles); + result.AddRange(cacheItem.Files); + localBundleFiles.Clear(); + } + + return result.Union(dynamicResources).ToImmutableList(); + } + + private BundleCacheItem AddToBundleCache(string bundleName, IBundler bundler, List bundleFiles) + { var bundleRelativePath = Options.BundleFolderName.EnsureEndsWith('/') + bundleName + "." + bundleFiles.JoinAsString("|").ToMd5() + "." + bundler.FileExtension; - var cacheItem = BundleCache.GetOrAdd(bundleRelativePath, () => + return BundleCache.GetOrAdd(bundleRelativePath, () => { var cacheValue = new BundleCacheItem( - new List + new List { - "/" + bundleRelativePath + new BundleFile("/" + bundleRelativePath) } ); @@ -104,8 +138,6 @@ public class BundleManager : IBundleManager, ITransientDependency return cacheValue; }); - - return cacheItem.Files.Union(dynamicResources).ToImmutableList(); } private void WatchChanges(BundleCacheItem cacheValue, List files, string bundleRelativePath) @@ -176,7 +208,7 @@ public class BundleManager : IBundleManager, ITransientDependency } } - protected async Task> GetBundleFilesAsync(List contributors) + protected async Task> GetBundleFilesAsync(List contributors) { var context = CreateBundleConfigurationContext(); @@ -198,7 +230,7 @@ public class BundleManager : IBundleManager, ITransientDependency return context.Files; } - protected virtual async Task> GetDynamicResourcesAsync(List contributors) + protected virtual async Task> GetDynamicResourcesAsync(List contributors) { var context = CreateBundleConfigurationContext(); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs index b4ce56cb62..067554e102 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs @@ -5,7 +5,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public interface IBundleManager { - Task> GetStyleBundleFilesAsync(string bundleName); + Task> GetStyleBundleFilesAsync(string bundleName); - Task> GetScriptBundleFilesAsync(string bundleName); + Task> GetScriptBundleFilesAsync(string bundleName); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs index a247022674..1926cb48cf 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs @@ -3,10 +3,12 @@ using Microsoft.AspNetCore.Razor.TagHelpers; using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -63,18 +65,24 @@ public abstract class AbpTagHelperResourceService : ITransientDependency foreach (var bundleFile in bundleFiles) { - var file = HostingEnvironment.WebRootFileProvider.GetFileInfo(bundleFile); - - if (file == null || !file.Exists) + if (bundleFile.IsCdn) { - Logger.LogError($"Could not find the bundle file '{bundleFile}' for the bundle '{bundleName}'!"); - AddErrorScript(viewContext, tagHelper, context, output, bundleFile, bundleName!); - continue; + AddHtmlTag(viewContext, tagHelper, context, output, bundleFile, null); } - - if (file.Length > 0) + else { - AddHtmlTag(viewContext, tagHelper, context, output, bundleFile + "?_v=" + file.LastModified.UtcTicks); + var file = HostingEnvironment.WebRootFileProvider.GetFileInfo(bundleFile.File); + if (file == null || !file.Exists) + { + Logger.LogError($"Could not find the bundle file '{bundleFile.File}' for the bundle '{bundleName}'!"); + AddErrorScript(viewContext, tagHelper, context, output, bundleFile, bundleName!); + continue; + } + + if (file.Length > 0) + { + AddHtmlTag(viewContext, tagHelper, context, output, bundleFile, file); + } } } @@ -84,13 +92,13 @@ public abstract class AbpTagHelperResourceService : ITransientDependency protected abstract void CreateBundle(string bundleName, List bundleItems); - protected abstract Task> GetBundleFilesAsync(string bundleName); + protected abstract Task> GetBundleFilesAsync(string bundleName); - protected abstract void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, string file); + protected abstract void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, BundleFile file, IFileInfo? fileInfo = null); - protected virtual void AddErrorScript(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, string file, string bundleName) + protected virtual void AddErrorScript(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, BundleFile file, string bundleName) { - output.Content.AppendHtml($"{Environment.NewLine}"); + output.Content.AppendHtml($"{Environment.NewLine}"); } protected virtual string GenerateBundleName(List bundleItems) 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 260f28f812..ec6ed2c99c 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 @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; @@ -32,12 +33,12 @@ public class AbpTagHelperScriptService : AbpTagHelperResourceService ); } - protected override async Task> GetBundleFilesAsync(string bundleName) + protected override async Task> GetBundleFilesAsync(string bundleName) { return await BundleManager.GetScriptBundleFilesAsync(bundleName); } - protected override void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, string file) + protected override void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, BundleFile file, IFileInfo? fileInfo = null) { var defer = tagHelper switch { @@ -46,12 +47,14 @@ public class AbpTagHelperScriptService : AbpTagHelperResourceService _ => false }; - var deferText = (defer || Options.DeferScriptsByDefault || Options.DeferScripts.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase))) + var deferText = (defer || Options.DeferScriptsByDefault || Options.DeferScripts.Any(x => file.File.StartsWith(x, StringComparison.OrdinalIgnoreCase))) ? "defer" : string.Empty; var nonceText = (viewContext.HttpContext.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceString && !string.IsNullOrEmpty(nonceString)) ? $"nonce=\"{nonceString}\"" : string.Empty; - output.Content.AppendHtml($"{Environment.NewLine}"); + + var src = file.IsCdn ? file.File : viewContext.GetUrlHelper().Content((file.File + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + output.Content.AppendHtml($"{Environment.NewLine}"); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs index 0f68433f4c..a43221841e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Security; @@ -18,7 +19,7 @@ public class AbpTagHelperStyleService : AbpTagHelperResourceService public AbpTagHelperStyleService( IBundleManager bundleManager, IOptions options, - IWebHostEnvironment hostingEnvironment, + IWebHostEnvironment hostingEnvironment, IOptions securityHeadersOptions) : base( bundleManager, options, @@ -36,12 +37,12 @@ public class AbpTagHelperStyleService : AbpTagHelperResourceService ); } - protected override async Task> GetBundleFilesAsync(string bundleName) + protected override async Task> GetBundleFilesAsync(string bundleName) { return await BundleManager.GetStyleBundleFilesAsync(bundleName); } - protected override void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, string file) + protected override void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, BundleFile file, IFileInfo? fileInfo = null) { var preload = tagHelper switch { @@ -50,15 +51,16 @@ public class AbpTagHelperStyleService : AbpTagHelperResourceService _ => false }; - if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase))) + var href = file.IsCdn ? file.File : viewContext.GetUrlHelper().Content((file.File + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.File.StartsWith(x, StringComparison.OrdinalIgnoreCase))) { output.Content.AppendHtml(SecurityHeadersOptions.UseContentSecurityPolicyScriptNonce - ? $"{Environment.NewLine}" - : $"{Environment.NewLine}"); + ? $"{Environment.NewLine}" + : $"{Environment.NewLine}"); } else { - output.Content.AppendHtml($"{Environment.NewLine}"); + output.Content.AppendHtml($"{Environment.NewLine}"); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/IWebRequestResources.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/IWebRequestResources.cs index 2eefbcc0dd..9479dec8ce 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/IWebRequestResources.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/IWebRequestResources.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; +using Volo.Abp.AspNetCore.Mvc.UI.Bundling; namespace Volo.Abp.AspNetCore.Mvc.UI.Resources; public interface IWebRequestResources { - List TryAdd(List resources); + List TryAdd(List resources); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/WebRequestResources.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/WebRequestResources.cs index 3e046499ab..e68b671fc6 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/WebRequestResources.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Resources/WebRequestResources.cs @@ -1,23 +1,24 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http; +using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Mvc.UI.Resources; public class WebRequestResources : IWebRequestResources, IScopedDependency { - protected Dictionary> Resources { get; } + protected Dictionary> Resources { get; } protected IHttpContextAccessor HttpContextAccessor { get; } public WebRequestResources(IHttpContextAccessor httpContextAccessor) { HttpContextAccessor = httpContextAccessor; - Resources = new Dictionary>(); + Resources = new Dictionary>(); } - public List TryAdd(List resources) + public List TryAdd(List resources) { var path = HttpContextAccessor.HttpContext?.Request?.Path ?? ""; From aa1d939200f79993f23f17f148e15e22e1c8ae6b Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 17 Oct 2023 20:12:06 +0800 Subject: [PATCH 2/5] 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}"); } } From 519b300ef2fde8e78c39cd4147c095590363c137 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 18 Oct 2023 09:50:47 +0800 Subject: [PATCH 3/5] Add `is-cdn` to script/style taghelper. --- .../Bundling/BundleConfigurationExtensions.cs | 6 ++++ .../BundleContributorCollectionExtensions.cs | 6 ++++ .../AspNetCore/Mvc/UI/Bundling/BundleFile.cs | 14 ++++++-- .../Mvc/UI/Bundling/BundleFileContributor.cs | 2 +- .../UI/Bundling/BundleFileListExtensions.cs | 32 ------------------- .../Mvc/UI/Bundling/BundleManager.cs | 2 +- .../TagHelpers/AbpBundleItemTagHelper.cs | 6 +++- .../TagHelpers/AbpTagHelperResourceService.cs | 6 ++-- .../TagHelpers/AbpTagHelperScriptService.cs | 4 +-- .../TagHelpers/AbpTagHelperStyleService.cs | 4 +-- .../TagHelpers/BundleTagHelperFileItem.cs | 6 ++-- .../SharedThemeGlobalScriptContributor.cs | 22 ++++++------- .../SharedThemeGlobalStyleContributor.cs | 8 ++--- 13 files changed, 55 insertions(+), 63 deletions(-) delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs index ca628f4d67..8dd51dc5a3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs @@ -11,6 +11,12 @@ public static class BundleConfigurationExtensions return bundleConfiguration; } + public static BundleConfiguration AddFiles(this BundleConfiguration bundleConfiguration, params BundleFile[] files) + { + bundleConfiguration.Contributors.AddFiles(files); + return bundleConfiguration; + } + public static BundleConfiguration AddCdnFiles(this BundleConfiguration bundleConfiguration, params string[] files) { bundleConfiguration.Contributors.AddCdnFiles(files.Select(x => new BundleFile(x, true)).ToArray()); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs index 3c0dfdeab8..22bfe2947c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs @@ -6,6 +6,12 @@ public static class BundleContributorCollectionExtensions { contributors.Add(new BundleFileContributor(files)); } + + public static void AddFiles(this BundleContributorCollection contributors, params BundleFile[] files) + { + contributors.Add(new BundleFileContributor(files)); + } + public static void AddCdnFiles(this BundleContributorCollection contributors, params BundleFile[] files) { contributors.Add(new BundleFileContributor(files)); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs index 58427b6c40..091a4b3823 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs @@ -2,13 +2,21 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public class BundleFile { - public string File { get; set; } + public string FileName { get; set; } public bool IsCdn { get; set; } - public BundleFile(string file, bool isCdn = false) + public BundleFile(string fileName, bool isCdn = false) { - File = file; + FileName = fileName; IsCdn = isCdn; } + + /// + /// This method is used to compatible with old code. + /// + public static implicit operator BundleFile(string fileName) + { + return new BundleFile(fileName); + } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs index 5107c006a0..df55266110 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileContributor.cs @@ -24,7 +24,7 @@ public class BundleFileContributor : BundleContributor { foreach (var file in Files) { - context.Files.AddIfNotContains(x => x.File.Equals(file.File, StringComparison.OrdinalIgnoreCase), () => file); + context.Files.AddIfNotContains(x => x.FileName.Equals(file.FileName, StringComparison.OrdinalIgnoreCase), () => file); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs deleted file mode 100644 index b3088b293d..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFileListExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; - -/// -/// This class is used to compatible with old code. -/// -public static class BundleFileListExtensions -{ - public static void Add(this List bundleFiles, params string[] files) - { - bundleFiles.AddRange(files.Select(file => new BundleFile(file))); - } - - public static void AddRange(this List bundleFiles, params string[] files) - { - bundleFiles.AddRange(files.Select(file => new BundleFile(file))); - } - - public static void AddIfNotContains(this List bundleFiles, params string[] files) - { - foreach (var file in files) - { - if (!bundleFiles.Any(x => x.File.Equals(file, StringComparison.OrdinalIgnoreCase))) - { - bundleFiles.Add(new BundleFile(file)); - } - } - } -} 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 fb7b3cd489..9e5ca4bdef 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 @@ -83,7 +83,7 @@ public class BundleManager : IBundleManager, ITransientDependency { if (!bundleFile.IsCdn) { - localBundleFiles.Add(bundleFile.File); + localBundleFiles.Add(bundleFile.FileName); } else { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs index 1240dbef11..81c06df7c3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.AspNetCore.Razor.TagHelpers; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers; @@ -17,6 +18,9 @@ public abstract class AbpBundleItemTagHelper : Ab /// public Type? Type { get; set; } + [HtmlAttributeName("is-cdn")] + public bool IsCdn { get; set; } + protected AbpBundleItemTagHelper(TTagHelperService service) : base(service) { @@ -49,7 +53,7 @@ public abstract class AbpBundleItemTagHelper : Ab if (Src != null) { - return new BundleTagHelperFileItem(Src); + return new BundleTagHelperFileItem(new BundleFile(Src, IsCdn)); } throw new AbpException("abp-script tag helper requires to set either src or type!"); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs index 1926cb48cf..5a19dee915 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs @@ -71,10 +71,10 @@ public abstract class AbpTagHelperResourceService : ITransientDependency } else { - var file = HostingEnvironment.WebRootFileProvider.GetFileInfo(bundleFile.File); + var file = HostingEnvironment.WebRootFileProvider.GetFileInfo(bundleFile.FileName); if (file == null || !file.Exists) { - Logger.LogError($"Could not find the bundle file '{bundleFile.File}' for the bundle '{bundleName}'!"); + Logger.LogError($"Could not find the bundle file '{bundleFile.FileName}' for the bundle '{bundleName}'!"); AddErrorScript(viewContext, tagHelper, context, output, bundleFile, bundleName!); continue; } @@ -98,7 +98,7 @@ public abstract class AbpTagHelperResourceService : ITransientDependency protected virtual void AddErrorScript(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, BundleFile file, string bundleName) { - output.Content.AppendHtml($"{Environment.NewLine}"); + output.Content.AppendHtml($"{Environment.NewLine}"); } protected virtual string GenerateBundleName(List bundleItems) 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 3ff8e05552..ea0f11b777 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 @@ -47,13 +47,13 @@ public class AbpTagHelperScriptService : AbpTagHelperResourceService _ => false }; - 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.FileName.StartsWith(x, StringComparison.OrdinalIgnoreCase))) ? "defer " : string.Empty; var nonceText = (viewContext.HttpContext.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceString && !string.IsNullOrEmpty(nonceString)) ? $"nonce=\"{nonceString}\" " : string.Empty; - var src = file.IsCdn ? file.File : viewContext.GetUrlHelper().Content((file.File + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + var src = file.IsCdn ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); output.Content.AppendHtml($"{Environment.NewLine}"); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs index a43221841e..63f2e2304d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs @@ -51,8 +51,8 @@ public class AbpTagHelperStyleService : AbpTagHelperResourceService _ => false }; - var href = file.IsCdn ? file.File : viewContext.GetUrlHelper().Content((file.File + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); - if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.File.StartsWith(x, StringComparison.OrdinalIgnoreCase))) + var href = file.IsCdn ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.FileName.StartsWith(x, StringComparison.OrdinalIgnoreCase))) { output.Content.AppendHtml(SecurityHeadersOptions.UseContentSecurityPolicyScriptNonce ? $"{Environment.NewLine}" diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/BundleTagHelperFileItem.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/BundleTagHelperFileItem.cs index 45ab8b64eb..b5f6ca74aa 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/BundleTagHelperFileItem.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/BundleTagHelperFileItem.cs @@ -5,16 +5,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers; public class BundleTagHelperFileItem : BundleTagHelperItem { [NotNull] - public string File { get; } + public BundleFile File { get; } - public BundleTagHelperFileItem([NotNull] string file) + public BundleTagHelperFileItem([NotNull] BundleFile file) { File = Check.NotNull(file, nameof(file)); } public override string ToString() { - return File; + return File.FileName; } public override void AddToConfiguration(BundleConfiguration configuration) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs index 2ac299959a..2ca7c191c8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs @@ -35,20 +35,20 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling; )] public class SharedThemeGlobalScriptContributor : BundleContributor { - + public override void ConfigureBundle(BundleConfigurationContext context) { - context.Files.AddRange(new[] + context.Files.AddRange(new BundleFile[] { - "/libs/abp/aspnetcore-mvc-ui-theme-shared/ui-extensions.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/jquery-extensions.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery-form/jquery-form-extensions.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/widget-manager.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/modal-manager.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert2/abp-sweetalert2.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/toastr/abp-toastr.js" + "/libs/abp/aspnetcore-mvc-ui-theme-shared/ui-extensions.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/jquery-extensions.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery-form/jquery-form-extensions.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/widget-manager.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/modal-manager.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert2/abp-sweetalert2.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/toastr/abp-toastr.js" }); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs index 01f490425c..f959d73f05 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs @@ -27,10 +27,10 @@ public class SharedThemeGlobalStyleContributor : BundleContributor { public override void ConfigureBundle(BundleConfigurationContext context) { - context.Files.AddRange(new[] + context.Files.AddRange(new BundleFile[] { - "/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-styles.css", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/date-range-picker/date-range-picker-styles.css" - }); + "/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-styles.css", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/date-range-picker/date-range-picker-styles.css" + }); } } From 8df549aed9a64c59ceb2d9f6af878bc2aed3d355 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 18 Oct 2023 10:22:34 +0800 Subject: [PATCH 4/5] Update `Bundling-Minification.md`. --- .../en/UI/AspNetCore/Bundling-Minification.md | 77 ++++++++++++++++++ .../UI/AspNetCore/Bundling-Minification.md | 78 +++++++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/docs/en/UI/AspNetCore/Bundling-Minification.md b/docs/en/UI/AspNetCore/Bundling-Minification.md index dd2282c883..650d3e3e77 100644 --- a/docs/en/UI/AspNetCore/Bundling-Minification.md +++ b/docs/en/UI/AspNetCore/Bundling-Minification.md @@ -382,6 +382,83 @@ Configure(options => ```` +### CDN Support + +You can configure `AbpBundlingOptions` or use `is-cdn` on `script/style` taghelper to load all or a single js/css file from CDN. + +#### Add CDN files in `AbpBundlingOptions` + +````csharp +Configure(options => +{ + options.StyleBundles + .Add("MyStyleBundle", configuration => + { + configuration + .AddFiles("/styles/my-style1.css") + .AddFiles("/styles/my-style2.css") + .AddCdnFiles("https://cdn.abp.io/bootstrap.css") + .AddFiles("/styles/my-style3.css") + .AddFiles("/styles/my-style4.css"); + }); + + options.ScriptBundles + .Add("MyScriptBundle", configuration => + { + configuration + .AddFiles("/scripts/my-script1.js") + .AddFiles("/scripts/my-script2.js") + .AddCdnFiles("https://cdn.abp.io/bootstrap.js") + .AddFiles("/scripts/my-script3.js") + .AddFiles("/scripts/my-script4.js"); + }); +}); +```` + +**Output HTML:** + +````html + + + + + + + +```` + +#### Add CDN files in Tag Helpers. + +````html + + + + + + + + + + + + + + + +```` + +**Output HTML:** + +````html + + + + + + + +```` + ## Themes Themes uses the standard package contributors to add library resources to page layouts. Themes may also define some standard/global bundles, so any module can contribute to these standard/global bundles. See the [theming documentation](Theming.md) for more. diff --git a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md index 338afe8967..fab0893a76 100644 --- a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md +++ b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md @@ -353,6 +353,84 @@ services.Configure(options => }); ```` +### CDN 支持 + +你可以配置`AbpBundlingOptions`或在`script/style` taghelper上使用`is-cdn`来从CDN加载js/css. + +#### 在`AbpBundlingOptions`中添加CDN文件 + +````csharp +Configure(options => +{ + options.StyleBundles + .Add("MyStyleBundle", configuration => + { + configuration + .AddFiles("/styles/my-style1.css") + .AddFiles("/styles/my-style2.css") + .AddCdnFiles("https://cdn.abp.io/bootstrap.css") + .AddFiles("/styles/my-style3.css") + .AddFiles("/styles/my-style4.css"); + }); + + options.ScriptBundles + .Add("MyScriptBundle", configuration => + { + configuration + .AddFiles("/scripts/my-script1.js") + .AddFiles("/scripts/my-script2.js") + .AddCdnFiles("https://cdn.abp.io/bootstrap.js") + .AddFiles("/scripts/my-script3.js") + .AddFiles("/scripts/my-script4.js"); + }); +}); +```` + +**输出HTMl:** + +````html + + + + + + + +```` + +#### 在TagHelpers中添加CDN文件 + +````html + + + + + + + + + + + + + + + +```` + +**输出HTMl:** + +````html + + + + + + + +```` + + ### 主题 主题使用标准包贡献者将库资源添加到页面布局. 主题还可以定义一些标准/全局包, 因此任何模块都可以为这些标准/全局包做出贡献. 有关更多信息, 请参阅[主题文档](Theming.md). From 9db31e75b4f890f1141fc7fb1caf536a3d693aa0 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 9 Nov 2023 17:13:52 +0800 Subject: [PATCH 5/5] Rename `CDN` to `External`. --- docs/en/UI/AspNetCore/Bundling-Minification.md | 16 ++++++++-------- .../UI/AspNetCore/Bundling-Minification.md | 17 ++++++++--------- .../Bundling/BundleConfigurationExtensions.cs | 4 ++-- .../BundleContributorCollectionExtensions.cs | 2 +- .../AspNetCore/Mvc/UI/Bundling/BundleFile.cs | 15 ++++++++++++--- .../AspNetCore/Mvc/UI/Bundling/BundleManager.cs | 2 +- .../TagHelpers/AbpBundleItemTagHelper.cs | 5 +---- .../TagHelpers/AbpTagHelperResourceService.cs | 2 +- .../TagHelpers/AbpTagHelperScriptService.cs | 2 +- .../TagHelpers/AbpTagHelperStyleService.cs | 2 +- 10 files changed, 36 insertions(+), 31 deletions(-) diff --git a/docs/en/UI/AspNetCore/Bundling-Minification.md b/docs/en/UI/AspNetCore/Bundling-Minification.md index 650d3e3e77..6164d00c7d 100644 --- a/docs/en/UI/AspNetCore/Bundling-Minification.md +++ b/docs/en/UI/AspNetCore/Bundling-Minification.md @@ -382,11 +382,11 @@ Configure(options => ```` -### CDN Support +### External/CDN file Support -You can configure `AbpBundlingOptions` or use `is-cdn` on `script/style` taghelper to load all or a single js/css file from CDN. +The bundling system automatically recognizes the external/CDN files and adds them to the page without any change. -#### Add CDN files in `AbpBundlingOptions` +#### Using External/CDN files in `AbpBundlingOptions` ````csharp Configure(options => @@ -397,7 +397,7 @@ Configure(options => configuration .AddFiles("/styles/my-style1.css") .AddFiles("/styles/my-style2.css") - .AddCdnFiles("https://cdn.abp.io/bootstrap.css") + .AddFiles("https://cdn.abp.io/bootstrap.css") .AddFiles("/styles/my-style3.css") .AddFiles("/styles/my-style4.css"); }); @@ -408,7 +408,7 @@ Configure(options => configuration .AddFiles("/scripts/my-script1.js") .AddFiles("/scripts/my-script2.js") - .AddCdnFiles("https://cdn.abp.io/bootstrap.js") + .AddFiles("https://cdn.abp.io/bootstrap.js") .AddFiles("/scripts/my-script3.js") .AddFiles("/scripts/my-script4.js"); }); @@ -427,13 +427,13 @@ Configure(options => ```` -#### Add CDN files in Tag Helpers. +#### Using External/CDN files in Tag Helpers. ````html - + @@ -441,7 +441,7 @@ Configure(options => - + diff --git a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md index fab0893a76..72bee2eedb 100644 --- a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md +++ b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md @@ -353,11 +353,11 @@ services.Configure(options => }); ```` -### CDN 支持 +### 外部/CDN文件支持 -你可以配置`AbpBundlingOptions`或在`script/style` taghelper上使用`is-cdn`来从CDN加载js/css. +捆绑系统会自动识别外部/CDN文件,并将其添加到页面中,无需进行任何更改。 -#### 在`AbpBundlingOptions`中添加CDN文件 +#### 在`AbpBundlingOptions`中添加外部/CDN文件 ````csharp Configure(options => @@ -368,7 +368,7 @@ Configure(options => configuration .AddFiles("/styles/my-style1.css") .AddFiles("/styles/my-style2.css") - .AddCdnFiles("https://cdn.abp.io/bootstrap.css") + .AddFiles("https://cdn.abp.io/bootstrap.css") .AddFiles("/styles/my-style3.css") .AddFiles("/styles/my-style4.css"); }); @@ -379,7 +379,7 @@ Configure(options => configuration .AddFiles("/scripts/my-script1.js") .AddFiles("/scripts/my-script2.js") - .AddCdnFiles("https://cdn.abp.io/bootstrap.js") + .AddFiles("https://cdn.abp.io/bootstrap.js") .AddFiles("/scripts/my-script3.js") .AddFiles("/scripts/my-script4.js"); }); @@ -398,13 +398,13 @@ Configure(options => ```` -#### 在TagHelpers中添加CDN文件 +#### 在TagHelpers中添加外部/CDN文件 ````html - + @@ -412,7 +412,7 @@ Configure(options => - + @@ -430,7 +430,6 @@ Configure(options => ```` - ### 主题 主题使用标准包贡献者将库资源添加到页面布局. 主题还可以定义一些标准/全局包, 因此任何模块都可以为这些标准/全局包做出贡献. 有关更多信息, 请参阅[主题文档](Theming.md). diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs index 8dd51dc5a3..62f7950c5a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs @@ -17,9 +17,9 @@ public static class BundleConfigurationExtensions return bundleConfiguration; } - public static BundleConfiguration AddCdnFiles(this BundleConfiguration bundleConfiguration, params string[] files) + public static BundleConfiguration AddExternalFiles(this BundleConfiguration bundleConfiguration, params string[] files) { - bundleConfiguration.Contributors.AddCdnFiles(files.Select(x => new BundleFile(x, true)).ToArray()); + bundleConfiguration.Contributors.AddExternalFiles(files.Select(x => new BundleFile(x, true)).ToArray()); return bundleConfiguration; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs index 22bfe2947c..addbe7e2cd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs @@ -12,7 +12,7 @@ public static class BundleContributorCollectionExtensions contributors.Add(new BundleFileContributor(files)); } - public static void AddCdnFiles(this BundleContributorCollection contributors, params BundleFile[] files) + public static void AddExternalFiles(this BundleContributorCollection contributors, params BundleFile[] files) { contributors.Add(new BundleFileContributor(files)); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs index 091a4b3823..fbd6c3eaa1 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs @@ -1,15 +1,24 @@ +using System; + namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public class BundleFile { public string FileName { get; set; } - public bool IsCdn { get; set; } + public bool IsExternalFile { get; set; } + + public BundleFile(string fileName) + { + FileName = fileName; + IsExternalFile = fileName.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || + fileName.StartsWith("https://", StringComparison.OrdinalIgnoreCase); + } - public BundleFile(string fileName, bool isCdn = false) + public BundleFile(string fileName, bool isExternalFile) { FileName = fileName; - IsCdn = isCdn; + IsExternalFile = isExternalFile; } /// 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 9e5ca4bdef..20c33e86e5 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 @@ -81,7 +81,7 @@ public class BundleManager : IBundleManager, ITransientDependency var localBundleFiles = new List(); foreach (var bundleFile in bundleFiles) { - if (!bundleFile.IsCdn) + if (!bundleFile.IsExternalFile) { localBundleFiles.Add(bundleFile.FileName); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs index 81c06df7c3..03ed327dc0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs @@ -18,9 +18,6 @@ public abstract class AbpBundleItemTagHelper : Ab /// public Type? Type { get; set; } - [HtmlAttributeName("is-cdn")] - public bool IsCdn { get; set; } - protected AbpBundleItemTagHelper(TTagHelperService service) : base(service) { @@ -53,7 +50,7 @@ public abstract class AbpBundleItemTagHelper : Ab if (Src != null) { - return new BundleTagHelperFileItem(new BundleFile(Src, IsCdn)); + return new BundleTagHelperFileItem(new BundleFile(Src)); } throw new AbpException("abp-script tag helper requires to set either src or type!"); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs index 5a19dee915..9be91c535f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs @@ -65,7 +65,7 @@ public abstract class AbpTagHelperResourceService : ITransientDependency foreach (var bundleFile in bundleFiles) { - if (bundleFile.IsCdn) + if (bundleFile.IsExternalFile) { AddHtmlTag(viewContext, tagHelper, context, output, bundleFile, null); } 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 ea0f11b777..c8486ebadd 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 @@ -53,7 +53,7 @@ public class AbpTagHelperScriptService : AbpTagHelperResourceService var nonceText = (viewContext.HttpContext.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceString && !string.IsNullOrEmpty(nonceString)) ? $"nonce=\"{nonceString}\" " : string.Empty; - var src = file.IsCdn ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + var src = file.IsExternalFile ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); output.Content.AppendHtml($"{Environment.NewLine}"); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs index 63f2e2304d..bcfd7d95e2 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs @@ -51,7 +51,7 @@ public class AbpTagHelperStyleService : AbpTagHelperResourceService _ => false }; - var href = file.IsCdn ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + var href = file.IsExternalFile ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.FileName.StartsWith(x, StringComparison.OrdinalIgnoreCase))) { output.Content.AppendHtml(SecurityHeadersOptions.UseContentSecurityPolicyScriptNonce