Bundle Transformer in ASP.NET Web Application (NOT MVC)

951 Views Asked by At

I would like to minify and obfuscate javascript files of my Web Application (not MVC). I based my code on this simple configuration: https://bundletransformer.codeplex.com/discussions/541419, but it seems to have no effect on js files when viewed from the browser. I did not understand if Bundle Transformer is only applicable to MVC Web Applications. I installed BundleTransformer.Core, BundleTransformer.Yui, Microsoft.AspNet.Web.Optimization.

Global.asax.cs:

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        var nullOrderer = new NullOrderer();
        var scriptBundle = new CustomScriptBundle("~/jscbundle/");
        scriptBundle.Include("~/js/main.js");
        scriptBundle.IncludeDirectory("~/js/", "*.js", true);
        scriptBundle.Orderer = nullOrderer;
        bundles.Add(scriptBundle);
        BundleTable.EnableOptimizations = true;
    }
}

protected void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Web.Config:

<system.web>
  <compilation debug="false" targetFramework="4.5" />
  ...
</system.web>

<bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
  <core>
    <css>
      <minifiers>
        <add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
        <add name="YuiCssMinifier" type="BundleTransformer.Yui.Minifiers.YuiCssMinifier, BundleTransformer.Yui" />
      </minifiers>
      <translators>
        <add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
      </translators>
    </css>
    <js defaultMinifier="YuiJsMinifier">
      <minifiers>
        <add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
        <add name="YuiJsMinifier" type="BundleTransformer.Yui.Minifiers.YuiJsMinifier, BundleTransformer.Yui" />
      </minifiers>
      <translators>
        <add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
      </translators>
    </js>
  </core>
</bundleTransformer>
2

There are 2 best solutions below

0
Arpit Goyal On

Bundle and Minify comes by default in normal Asp.net project in VS2015 onwards.

Minify is not restricted to MVC, we can use it for any files.
In Android , we can obfuscate the complete project.

Please let me know which version of VS are you using ? so i can provide assistance accordingly.

0
Andrey Taritsyn On

I recommend you to read the Rick Anderson's posts about using of Microsoft ASP.NET Web Optimization Framework with Web Forms and Web Pages.