10

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:

enter image description here

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)

enter image description here

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?!

11
  • This may just be a mismatch in your screenshots, but the paths listed in the errors are showing your scripts directly under the javascript folder instead of the subfolders shown in your directory structure screenshot. Commented Aug 23, 2014 at 1:52
  • Both screen shots were just taken as is. That's what is super odd.. I'll double check just in case.. Commented Aug 23, 2014 at 1:53
  • yep - just checked and that's exactly what it's showing... Commented Aug 23, 2014 at 1:57
  • Any chance those files exist in the javascript root folder just hidden due to not being in the project? Commented Aug 23, 2014 at 1:58
  • Nope. And the .js files it's listing are the exact ones within my javascript folder structure. not sure if it's related to some handler in the config, though played around with those too Commented Aug 23, 2014 at 2:00

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Well - I just upgraded to the latest 1.1.3 and voila! It worked! you know, it's the last thing i would have thought to look at; the version - kinda expect this sort of thing to work after so many revisions. I'm going to mark yours as answered. A) Because of the great help B) it was my version number c) well.. i'm a happy bunny now :D Thanks bud
Ah glad to help. Didn't realize upgrade was an option as well:)
yah, neither did i :) - tried downgrading first which just killed everything then noticed i was 2 versions behind on this project :) thanks again :)
2

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

Comments

0

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?

4 Comments

Not true. The third parameter in the bundle true tells bundling to search sub folders. This is the structure I always use and never have an issue with until now.
Look at the overload he's using...
Where are you rendering the bundles?
Same place as i always do - _layout.cshtml just before the closing body - the css bundle is working as-is
0

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"));

1 Comment

Your issue here is you're bundling min versions of the file. Bundling doesn't work with files that have min in the filename.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.