Automate minfication using System.Web.Optimization & WebGrease in asp.net mvc without bundling

1.5k Views Asked by At

I have used System.Web.Optimization & WebGrease DLL to do automate bundle and minifiy javascript and css files in my project using below code.

using System.Web.Optimization;
using WebGrease;

protected void Application_Start()
{
    RegisterBundles(BundleTable.Bundles);
    BundleTable.EnableOptimizations = false;

}
public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/Content/Script/Common/").Include("~/Content/Scripts/PTax/Common/ViewPort.js",
                                                                        "~/Content/Scripts/PTax/Common/jquery.rotate.js",
                                                                        "~/Content/Scripts/PTax/Common/jquery.loupe.js",
                                                                        "~/Content/Scripts/PTax/Common/Accordion.js",
                                                                        "~/Content/Scripts/PTax/Common/Progress.js",
                                                                        "~/Content/Scripts/PTax/Common/AjaxGlobalHandler.js",
                                                                        "~/Content/Scripts/PTax/Common/DialogBox.js",
                                                                        "~/Content/Scripts/PTax/Common/Common.js",
                                                                        "~/Content/Scripts/PTax/Common/DateValidations.js"));

}

In my project some module having only one javascript file. I don need to bundle that with anyother files. So i just need it minifiy it. How can i do that.

1

There are 1 best solutions below

2
On

You can create a new bundle, (it's normal to create multiple bundles)

bundles.Add(new ScriptBundle("~/bundles/get").Include("~/Scripts/app/home.js"));

Then render the scripts in the necessary views

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