Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 System.Web.Optimization Bundles single file

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?
like image 838
jaap Avatar asked Feb 19 '12 21:02

jaap


1 Answers

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:

  • http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx
like image 182
Meligy Avatar answered Oct 29 '22 00:10

Meligy