0

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.

James
  • 2,195
  • 1
  • 19
  • 22
Harishankaran
  • 111
  • 1
  • 1
  • 12

1 Answers1

0

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")
Lee Gary
  • 2,357
  • 2
  • 22
  • 38
  • Can i do automatic minification in corresponding view itself without adding line like you said in global.asax file. – Harishankaran Feb 19 '14 at 08:34
  • Not that i know of, webgrease takes the file that you specified and doing minification & combining them into 1, if you do not specify the files, how can webgrease know what to bundle & minify? In some part of your views, there should be `~/Content/Script/Common/`? You can also specify another _Layouts.cshtml in the folder of the view & exclude the common bundle – Lee Gary Feb 19 '14 at 08:42