I have created bundling in my project as follows : Have created a config under App_Start/BundleConfig.cs
public class BundleConfig
{
[UsedImplicitly]
public virtual void Process(PipelineArgs args)
{
RegisterBundles(BundleTable.Bundles);
}
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/js").Include("~/Assets/Project/scripts/main.js"));
bundles.Add(new StyleBundle("~/bundles/css").Include("~/Assets/Project/styles/main.css"));
}
}
and added the same in Pipeline
<initialize>
<processor type="MyProject.Foundation.Assets.App_Start.BundleConfig, MyProject.Foundation.Assets" patch:before="processor[@type='Sitecore.Pipelines.Loader.ShowVersion, Sitecore.Kernel']" />
</initialize>
So the bundling is working fine as expected.
But now I need to optimize them using a query parameter in the URL, example if I browse example.local?debug=true, I need to enable optimizations as false
So now I have added another config
public class BundleOptimizations : HttpRequestProcessor
{
public override void Process(HttpRequestArgs args)
{
EnableOptimizations();
}
public void EnableOptimizations()
{
var debugMode = HttpContext.Current.Request.QueryString["debug"];
if (!string.IsNullOrEmpty(debugMode) && string.Equals(debugMode, "true", StringComparison.InvariantCultureIgnoreCase))
{
BundleTable.EnableOptimizations = false;
}
else
{
BundleTable.EnableOptimizations = true;
}
}
}
and this config I have added in HttpRequestBegin pipeline
<httpRequestBegin>
<processor type="MyProject.Foundation.Assets.App_Start.BundleOptimizations, MyProject.Foundation.Assets" patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel']" />
</httpRequestBegin>
But I am not able to get these bundles optimized using the query parameter. Please can someone help me with the same
Thanks