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.
You can create a new bundle, (it's normal to create multiple bundles)
Then render the scripts in the necessary views