简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM