renathy
renathy

Reputation: 5355

Add bundling to ASP .NET web forms

I had .NET 4 Web Site. I moved it to .NET 4.5.

Now I want to know if I can use Bundles (for js and css files) within WebSite project (that was just migrated to 4.5.).

Is it possible?

If yes - I believe that should be done in global.asax (as App_Start doesn't exist in website project). But which references should I add?

Upvotes: 1

Views: 2719

Answers (1)

MAlvarez
MAlvarez

Reputation: 96

You need to include this library in your Global.asax

Imports System.Web.Optimization

In your Application_Start event add something like this:

BundleTable.EnableOptimizations = True
BundleTable.Bundles.Add(New ScriptBundle("~/bundle/js").Include("~/jquery.min.js")
BundleTable.Bundles.Add(New StyleBundle("~/bundle/css").Include("~/styles.css")

In your MasteFiler add to the header section:

<%# Optimization.Scripts.Render("~/bundle/js")%>
<%# Optimization.Styles.Render("~/bundle/css")%>

Don't forget to remove the old markup where your were adding the CSS and JS before using the bundle feature.

Upvotes: 3

Related Questions