I gave it a try, only to find that it works great and I do not have to worry about having a .min version and “un”-.min version and which ones to deploy. The concept is simple. Forget both versions. Just send the full version and tell your application which scripts need to be bundled together and the .net framework does the rest. This is a sample exercise to create a bundling process for a web form’s web site. It is approximately the same for MVC but since I work a lot in web forms I thought I would provide steps to do it this way.
Create a New Visual Studio Visual Basic Web Form Application 4.0 (I called it Bundling)
—>Add the following references (You can get them from Github…see below in assets)
Open up the Global.asax file and add this to the top (Right above the Public Class Global_asax):
[code language=”vb”]Imports System.Web.Optimization[/code]
[code language=”vb”]Public Class BundleConfig
Public Shared Sub RegisterBundles(ByVal bundles As BundleCollection)
‘BundleTable.EnableOptimizations = True
bundles.Add(New ScriptBundle("~/bundles/home").Include("~/jsFile1.js", "~/jsFile2.js"))
bundles.Add(New ScriptBundle("~/bundles/home2").Include("~/jsFile1.js", "~/jsFile3.js"))
Open up the WebForm1.aspx and add the following to the page.
<%@ Import Namespace="System.Web.Optimization">
And then under the page add the following. The name here should match the name that you created above.
<!–This is the asp.net bundling script–>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
When you are done your project should look similar to this one.
Now you do not have to worry about changing anything when you deploy to production. To read more about bundling try this article.
Assets for this sample:
Drop me a line and let me know what you think or if I have missed anything
Looking for quality web hosting? Look no further than Arvixe Web Hosting!