profileOptionsBuilder)
+ {
+ if (string.IsNullOrEmpty(profileName))
+ throw new ArgumentNullException(nameof(profileName));
+
+ if (profileOptionsBuilder == null)
+ throw new ArgumentNullException(nameof(profileOptionsBuilder));
+
+ _profileBuilders.Add(profileName, profileOptionsBuilder);
+ return this;
+ }
+
///
/// Builds the bundle environment options based on the callbacks specified
///
@@ -39,16 +50,13 @@ public BundleEnvironmentOptions Build()
{
if (!_built)
{
- if (_debugBuilder != null)
- {
- _debugBuilder(new BundleOptionsBuilder(_bundleEnvironmentOptions.DebugOptions));
- }
- if (_productionBuilder != null)
+ foreach (var (profileName, profileBuilder) in _profileBuilders)
{
- _productionBuilder(new BundleOptionsBuilder(_bundleEnvironmentOptions.ProductionOptions));
+ BundleOptions options = _bundleEnvironmentOptions[profileName];
+ profileBuilder.Invoke(new BundleOptionsBuilder(options));
}
}
return _bundleEnvironmentOptions;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Smidge.Core/Options/SmidgeOptionsProfile.cs b/src/Smidge.Core/Options/SmidgeOptionsProfile.cs
new file mode 100644
index 0000000..d1c2416
--- /dev/null
+++ b/src/Smidge.Core/Options/SmidgeOptionsProfile.cs
@@ -0,0 +1,11 @@
+
+namespace Smidge.Options
+{
+ public static class SmidgeOptionsProfile
+ {
+ public const string Default = Production;
+
+ public const string Debug = "Debug";
+ public const string Production = "Production";
+ }
+}
diff --git a/src/Smidge.Web/Views/Home/Index.cshtml b/src/Smidge.Web/Views/Home/Index.cshtml
index 393d56b..4def666 100644
--- a/src/Smidge.Web/Views/Home/Index.cshtml
+++ b/src/Smidge.Web/Views/Home/Index.cshtml
@@ -38,12 +38,12 @@
@await Html.PartialAsync("TopBar")
- @await Html.PartialAsync("LoadedDependencies", false)
+ @await Html.PartialAsync("LoadedDependencies", (bool?)null)
- @await SmidgeHelper.JsHereAsync(debug: false)
+ @await SmidgeHelper.JsHereAsync()
@await SmidgeHelper.JsHereAsync("test-bundle-1")
@await SmidgeHelper.JsHereAsync("test-bundle-2")
- @await SmidgeHelper.JsHereAsync("no-files", debug: false)
+ @await SmidgeHelper.JsHereAsync("no-files")
@await SmidgeHelper.JsHereAsync("test-bundle-10")
diff --git a/src/Smidge.Web/Views/Home/SubFolder.cshtml b/src/Smidge.Web/Views/Home/SubFolder.cshtml
index fef9db5..97ef221 100644
--- a/src/Smidge.Web/Views/Home/SubFolder.cshtml
+++ b/src/Smidge.Web/Views/Home/SubFolder.cshtml
@@ -32,9 +32,9 @@
@await Html.PartialAsync("TopBar")
- @await Html.PartialAsync("LoadedDependencies", false)
+ @await Html.PartialAsync("LoadedDependencies", (bool?)null)
- @await SmidgeHelper.JsHereAsync(debug: false)
+ @await SmidgeHelper.JsHereAsync()
@await SmidgeHelper.JsHereAsync("test-bundle-1")
@await SmidgeHelper.JsHereAsync("test-bundle-2")
diff --git a/src/Smidge.Web/Views/Shared/LoadedDependencies.cshtml b/src/Smidge.Web/Views/Shared/LoadedDependencies.cshtml
index 21f36c1..77241e3 100644
--- a/src/Smidge.Web/Views/Shared/LoadedDependencies.cshtml
+++ b/src/Smidge.Web/Views/Shared/LoadedDependencies.cshtml
@@ -1,5 +1,7 @@
-@model bool
+@model bool?
+
@using Smidge.Models;
+
@inject Smidge.SmidgeHelper SmidgeHelper
@inject Smidge.IBundleManager BundleManager
@@ -43,4 +45,4 @@
JS loading debug output:
-
\ No newline at end of file
+
diff --git a/src/Smidge/Controllers/AddCompressionHeaderAttribute.cs b/src/Smidge/Controllers/AddCompressionHeaderAttribute.cs
index f2ca3fb..0c472d8 100644
--- a/src/Smidge/Controllers/AddCompressionHeaderAttribute.cs
+++ b/src/Smidge/Controllers/AddCompressionHeaderAttribute.cs
@@ -1,8 +1,9 @@
-using System;
+using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Smidge.Models;
+using Smidge.Options;
namespace Smidge.Controllers
{
@@ -17,6 +18,7 @@ public sealed class AddCompressionHeaderAttribute : Attribute, IFilterFactory, I
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
{
return new AddCompressionFilter(
+ serviceProvider.GetRequiredService(),
serviceProvider.GetRequiredService(),
serviceProvider.GetRequiredService());
}
@@ -27,11 +29,13 @@ public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
private class AddCompressionFilter : IActionFilter
{
+ private readonly ISmidgeProfileStrategy _profileStrategy;
private readonly IRequestHelper _requestHelper;
private readonly IBundleManager _bundleManager;
- public AddCompressionFilter(IRequestHelper requestHelper, IBundleManager bundleManager)
+ public AddCompressionFilter(ISmidgeProfileStrategy profileStrategy, IRequestHelper requestHelper, IBundleManager bundleManager)
{
+ _profileStrategy = profileStrategy ?? throw new ArgumentNullException(nameof(profileStrategy));
_requestHelper = requestHelper ?? throw new ArgumentNullException(nameof(requestHelper));
_bundleManager = bundleManager ?? throw new ArgumentNullException(nameof(bundleManager));
}
@@ -62,7 +66,22 @@ public void OnActionExecuted(ActionExecutedContext context)
//check if it's a bundle (not composite file)
if (file is BundleRequestModel bundleRequest && _bundleManager.TryGetValue(bundleRequest.FileKey, out var bundle))
{
- var bundleOptions = bundle.GetBundleOptions(_bundleManager, bundleRequest.Debug);
+ string profileName;
+
+ // For backwards compatibility we'll use the Debug profile if it was explicitly requested in the request.
+ if (bundleRequest.Debug)
+ {
+ profileName = SmidgeOptionsProfile.Debug;
+ }
+ else
+ {
+ // If the Bundle explicitly specifies a profile to use then use it otherwise use the current profile
+ profileName = !string.IsNullOrEmpty(bundle.ProfileName)
+ ? bundle.ProfileName
+ : _profileStrategy.GetCurrentProfileName();
+ }
+
+ var bundleOptions = bundle.GetBundleOptions(_bundleManager, profileName);
enableCompression = bundleOptions.CompressResult;
}
@@ -72,4 +91,4 @@ public void OnActionExecuted(ActionExecutedContext context)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Smidge/Controllers/AddExpiryHeadersAttribute.cs b/src/Smidge/Controllers/AddExpiryHeadersAttribute.cs
index 2929d58..b1db4c5 100644
--- a/src/Smidge/Controllers/AddExpiryHeadersAttribute.cs
+++ b/src/Smidge/Controllers/AddExpiryHeadersAttribute.cs
@@ -13,7 +13,10 @@ namespace Smidge.Controllers
///