Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC - Script Combine

The ASP.NET team released the script combining feature in 3.5 SP1 as detailed here http://www.asp.net/Learn/3.5-SP1/video-296.aspx. Is there a similar feature already for the MVC framework? If not, is this in scope or is it possible to somehow leverage the webforms capability in MVC? I see this site uses a custom jquery.package.master which, I assume, they have rolled themselves (maybe into the build cycle, however it is not all minified therefore I think they have manually appended the scripts together rather than some automated minify & combine task). Would be interested in any ideas how to accomplish this in MVC but I dont want to begin rolling any of my own functionality in case I will be duplicating work in progress.

like image 465
redsquare Avatar asked Nov 08 '08 08:11

redsquare


People also ask

How do I bundle a script in MVC?

In an ASP.NET MVC project, the BundleConfig class in the App Start folder can be used to generate style or script bundles. This method has a parameter bundle, which is of the type BundleCollection. At the start of the program, all of the bundles created are added to this bundle parameter.

What is bundling in MVC?

Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load performance.

What is BundleConfig Cs in ASP.NET MVC?

By default, the MVC application's BundleConfig (located inside App_Start folder) comes with the following code − public static void RegisterBundles(BundleCollection bundles) { // Following is the sample code to bundle all the css files in the project // The code to bundle other javascript files will also be similar to ...

What is the use of FilterConfig in MVC?

cs file by using default FilterConfig. RegisterGlobalFilters() method. The global filters will be applied to all the controller and action methods of an application. The [HandleError] filter is applied globally in the MVC application by default in every MVC application created using Visual Studio, as shown below.


3 Answers

Here's what I do, in case it's helpful.

In my postbuild I call a command line version of Dean Edwards's Packer. It combines the scripts and packs them for me.

For now though, I keep all of my stuff seperate and use a Helper method to include my scripts, and if the debug flag is not present it will include the packed versions, otherwise it includes the unpacked.

like image 131
Jeff Sheldon Avatar answered Oct 16 '22 20:10

Jeff Sheldon


Another option is in the Telerik Native UI Extensions for MVC (free library and open source), called ScriptRegistar. It will combine and compress javascript for you, and is fairly feature rich. There is also a class for doing the same to css as well.

I am using this to combine +20 javascript files into one file which is downloaded by the browser.

http://www.telerik.com/products/aspnet-mvc.aspx and you can get it via NuGet.

like image 44
Chris Brandsma Avatar answered Oct 16 '22 19:10

Chris Brandsma


Every day there is a different way of doing things and the techniques changes.

At this time there is a very good Nuget Package released in CodePlex.

Combres - WebForm & MVC Client-side Resource Combine Library
http://combres.codeplex.com/

http://weblogs.asp.net/gunnarpeipman/archive/2009/07/04/asp-net-mvc-how-to-combine-scripts-and-other-resources.aspx

like image 2
Mangesh Pimpalkar Avatar answered Oct 16 '22 19:10

Mangesh Pimpalkar