ASP.Net MVC Script Bundle results in 404

I searched for SO - found many questions, although none of the answers helped.

I created a bunch of sites and have not encountered this problem before.

Essentially, my script package results in 404 for each of the files in my javascript folder.

My structure (at the moment I changed a bunch of it!) Looks like this:

enter image description here

I do this, so I can guarantee that ASP.Net will not change the order - I can guarantee that some scripts are ahead of others. This is how I always did it, and it works fine.

My script package - for now - 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 tried a bunch of virtual paths.

My CSS loads perfectly. My Js - I get a list of 404; one for each of the * / js files.

Any ideas?

My console looks like this: it also shows me that bundles.FileSetOrderList.Clear(); doesn't actually clear my list, otherwise I will have jquery up to angular (like mine)

enter image description here

UPDATE

If I BundleTable.EnableOptimizations = true; in my bundles, then all this is connected, minimized and works - although this sucks for developing debugging - what really interferes with working in debug mode ?!

+7
asp.net-mvc bundling-and-minification
source share
4 answers

This post seems to describe the same issue. Problems with the ASP.NET MVC 5 subdirectory and is a known issue with version 1.1.1 in the Bundling framework.

If you do not want to update or update the version where it works, you always have the option to explicitly add files to the package that you want first. Say you have files in one folder.

 /javascript/lib/ascript.js /javascript/lib/ascript2.js /javascript/lib/jquery.js /javascript/lib/yscript.js 

You can explicitly specify the files you want first with the Include () function, and then still merge the rest together with IncludeDirectory ().

 bundles.Add(new ScriptBundle("~/bundles/jscript").Include( "~/javascript/lib/jquery.js", .IncludeDirectory("~/javascript/lib", "*.js") 

Addition is smart enough not to include double jQuery.js if it was explicitly added first. Similarly, you can have multiple .IncludeDirectory calls in different subdirectories if you want to keep them subfolders.

+3
source share

If you set the enable optimization flag to true, it will overwrite debug = false and bind it. just use the code snippet below in the bundle.config file to remove the binding in debug mode.

  #if !DEBUG BundleTable.EnableOptimizations = true; #endif 
+2
source share

I think these are subfolders. I am sure that the bundles only look into this direct folder. Have you used this folder structure of the package before and worked successfully?

0
source share

As already mentioned, I kept getting jquery 404 not found.

This is not a great answer, but this is what I agreed with until I find a better answer.

My problem was this: it worked very successfully locally in development.

 bundles.Add(new ScriptBundle("~/jquery").Include(new[] { "~/scripts/jquery-1.12.0.min.js", })); 

I tried the options and looked at the other options, in the end, I changed it to the next one for production. Googles CDN has always been reliable, there are 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")); 
0
source share

All Articles