I have been trying to implement bundling and minification for my existing asp.net webforms project and unfortunately it is ending up with 404 responses.
Let me first share the steps I have followed.
Installed
System.Web.Optimization
through nuget.Added
BundleConfig
class and registered it on Glabal.asax Application_Start event
My code to bundle the JS files.
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/modelJs").Include(
"~/src/model.js",
"~/src/calender.js",
"~/src/common.js",
"~/src/insurance.js"));
...
- Added following markup to aspx page
<asp:PlaceHolder runat="server"> <%: System.Web.Optimization.Scripts.Render("~/bundles/modelJs") %> </asp:PlaceHolder>
- set BundleTable.EnableOptimizations = true; in bundleConfig and the url formed is
http://localhost:9011/bundles/modelJs/?v=xNmmFhbzC1isUARLQne-XoBRkWBWApbnRQX8AGvNxQY1
I have also checked the sample project which gets added in VS2013 webforms application and surprisingly, it seems to be working fine.
I have seen many questions with similar problems on SO but was not able to solve it.
Well, the solution turns out to be very simple. Just added '/' after bundling folder which is
modeljs
in this case.Unfortunately, I didn't find this in any available source codes so I ended up wasting a lot of time. :-/