MVC 3 System.Web.Optimization Bundles single file

jaap picture jaap · Feb 19, 2012 · Viewed 7.3k times · Source

In MVC3 C# I'm trying the new System.Web.Optimization Bundles JSminify & CssMinify package (part of the .NET 4.5 framework).

I have one main Bundle. On one page in my website, I wish to include a single .js file only for that page. I would like to have it minified like the bundles, but it does not need to be bundled.

How can this be done?

  • Also, is the source and documentation available for this package?

Answer

Meligy picture Meligy · Feb 20, 2012

I think you need to add another bundle to it.

For example:

Bundle myJSBundle = new Bundle("~/combined-scripts/custom/my-page", 
                                                               typeof(JsMinify));
myJSBundle.AddFile("~/Scripts/Custom/MyPage.js");

Then in your page:

<script src="@Url.Content("~/combined-scripts/custom/my-page")" 
                                                 type="text/javascript"></script>

Reference: - http://www.dotnetexpertguide.com/2011/12/bundling-and-minification-aspnet-mvc4.html

More readings: