Search code examples
asp.net-mvcangularjsbundling-and-minification

Minification JS file on each and every *.cshtml page


The app I'm working on has been developed by using ASP.net MVC and AngularJs. It's not a SPA app.I need to do bundling and minification of my JS files.I know how to do it on "Layout page".For that I have used this Bundling and Minification tutorial.

But My question is how can I Minification my JS file on each and every *.cshtml page ? And I need that JS file as unminified when I do the debug.Can I achieve that ? Any help would be highly appreciated.

Here is my "index.cshtml" page with JS file resides on bottom of the page.I would like to do Minification this js file.

//removed html code for clarity
<script type="text/javascript" src="/Resources/js/controllers/MyTestController.js"> </script> 

Solution

  • Add a new ScriptBundle in BundleConfig.cs

    bundles.Add(new ScriptBundle("~/bundles/yourFile").Include(
      "..." // your file(s)
    ));
    

    and in you view

    @Scripts.Render("~/bundles/yourFile")