Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Bundles to existing ASP.NET Webforms solution

I am trying to add Bundles to an existing ASP.NET Webforms solution but my bundles always render empty and I am unsure why. I have been following this blog post.

So far I have:

  • Added the Microsoft ASP.NET Web Optimization Framework NuGet package
  • Ensured required references are included
  • Tried using debug="false" and debug="true" in Web.config
  • Added the following code to my solution

Global.asax.cs

protected void Application_Start(object sender, EventArgs e) {     BundleConfig.RegisterBundles(BundleTable.Bundles); } 

App_Start/BundleConfig.cs

public class BundleConfig {     // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951     public static void RegisterBundles(BundleCollection bundles)     {         bundles.Add(new ScriptBundle("~/bundles/Global").Include(             "~/js/jquery-{version}.js",             "~/js/jquery-ui.js"));          bundles.Add(new ScriptBundle("~/bundles/GlobalHead").Include(             "~/js/modernizr*"));          bundles.Add(new StyleBundle("~/Content/Global").Include(             "~/css/site.css"));     } } 

Site.Master

<head runat="server">     <asp:PlaceHolder runat="server">         <%: Scripts.Render("~/bundle/GlobalHead") %>         <%: Styles.Render("~/Content/Global") %>     </asp:PlaceHolder> </head> <body>     <%: Scripts.Render("~/bundle/Global") %> </body> 

Web.Config

<namespaces>     <add namespace="System.Web.Optimization" /> </namespaces> 

Update

To be clear, when I open a web page and inspect the resources with chrome dev tools, I can see

Content/Site.css bundle/Global.js bundle/GlobalHead.js 

But when inspecting them they have no content.

like image 972
Joe Avatar asked May 28 '15 14:05

Joe


People also ask

How do you override the bundling setting of web config?

To enable bundling and minification, set the debug value to "false". You can override the Web. config setting with the EnableOptimizations property on the BundleTable class. The following code enables bundling and minification and overrides any setting in the Web.

Can we use bundling and minification with ASP NET web forms like MVC?

To optimize the performance of an application I found that bundling and minification can significantly improve the performance. It can be applied on MVC as well as in ASP.NET web forms.

Is asp net webforms deprecated?

ASP.NET Web Forms is no longer an option for new development. It's shunned but not dead — supported as a legacy product, but finally exiled from the future of . NET.


1 Answers

Simple solution, I had some typing errors.

In the Site.Master I missed the 's' from the end of bundles. Making my Site.Master look like this.

<head runat="server">     <asp:PlaceHolder runat="server">         <%: Scripts.Render("~/bundles/GlobalHead") %>         <%: Styles.Render("~/Content/Global") %>     </asp:PlaceHolder> </head> <body>     <%: Scripts.Render("~/bundles/Global") %> </body> 
like image 135
Joe Avatar answered Oct 09 '22 01:10

Joe