Reputation: 30727
I've searched SO - found many of the same question, though none of the answers helped.
I've built a bunch of sites and not ran into this issue before.
Essentially, my script bundle results in a 404 for each of the files in my javascript folder.
My structure (at the moment, i've changed it a bunch!) looks like this:
I do this so i can guarantee that ASP.Net doesn't change the order - i can ensure certain scripts are ahead of others. It's how i've always done it and it normally works well.
My bundle script - at the moment - is:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.FileSetOrderList.Clear();
// stlyes
StyleBundle cssBundle = new StyleBundle("~/bundles/css");
cssBundle.IncludeDirectory("~/content/css", "*.css", true);
bundles.Add(cssBundle);
//scripts
ScriptBundle jsBundle = new ScriptBundle("~/bundles/jscript");
jsBundle.IncludeDirectory("~/content/javascript", "*.js", true);
bundles.Add(jsBundle);
}
I have tried a whole bunch of virtual paths.
My CSS loads perfect. My Js - i get a list of 404's; one for each of the */js files.
Any ideas?
My console looks like this - which also shows me that bundles.FileSetOrderList.Clear();
isn't actually clearing its list else i would have jquery before angular (as is my intent)
UPDATE
If i BundleTable.EnableOptimizations = true;
in my bundles then it's all bundled, minified and works - though this sucks for development debugging - what on earth is preventing it working in debug mode?!
Upvotes: 10
Views: 6906
Reputation: 387
If you set the enable optimization flag to true, it will overwrite the debug=false and bundle it. just use the below code snippet in your bundle.config file to remove bundling in debug mode.
#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif
Upvotes: 2
Reputation: 1193
As mentioned I kept getting jquery 404 not found.
This isn't a great answer but this is what I settled with until I find a better answer.
My issue was with the following, this worked very happily locally in development.
bundles.Add(new ScriptBundle("~/jquery").Include(new[]
{
"~/scripts/jquery-1.12.0.min.js",
}));
I tried variations and looked at the other options, in the end I changed it to the following for production. Googles CDN has always been reliable, there is other CDN options if you google around.
bundles.Add(new ScriptBundle("~/jquery", "https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"));
Upvotes: 0
Reputation: 12203
This post seems to describe the same problem ASP.Net MVC 5 sub-directory bundling issues and is a known issue with version 1.1.1 of the Bundling framework.
If you don't want to have to downgrade or upgrade to a version where this is working, you always have the option of explicitly adding files to the bundle that you want to come first. Let's say you have your files in the same folder.
/javascript/lib/ascript.js
/javascript/lib/ascript2.js
/javascript/lib/jquery.js
/javascript/lib/yscript.js
You can be explicit about the files you want first via Include(), and then still lump the rest together via IncludeDirectory().
bundles.Add(new ScriptBundle("~/bundles/jscript").Include(
"~/javascript/lib/jquery.js",
.IncludeDirectory("~/javascript/lib", "*.js")
The bundling is smart enough to not double include jQuery.js if it has been explicitly added first. Similarly, you can have multiple .IncludeDirectory calls on your various subdirectories if you want to still keep them sub-foldered.
Upvotes: 4
Reputation: 4652
I think that it is the nested folders. I'm pretty sure the bundles only look in that direct folder. Have you used that folder structure with bundling before and it worked successfully?
Upvotes: 0