Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1444 posts 1855 karma points
    Feb 19, 2015 @ 12:07
    Gordon Saxby
    0

    Visual Studio 2013 bundling not working

    I have the latest Umbraco 7.2.1 in a Visual Studio project (2013, MVC) and it is working OK ... except that bundling does not seem to work!?

    I added this:

        public class RegisterEvents : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                BundleConfig.RegisterBundles(BundleTable.Bundles);
    
                // Ensure it bundles even in Debug mode
                BundleTable.EnableOptimizations = true;
            }
        }

    Added the simplest bundle:

                bundles.Add(new StyleBundle("~/bundles/css").Include("~/Content/Site.css"));

    I get this in the HTML:

        <link href="/bundles/css?v=z9DjkMY9q_jvoOnQewWj0aE-trF4D-_3T7bpoT8Wins1" rel="stylesheet"/>

    But the link returns 404.

    I know this isn't strictly Umbraco related, but ... any ideas?!

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 19, 2015 @ 12:28
    Dave Woestenborghs
    0

    Can you post your entire code. The one of your BundleConfig class.

     

    Dave

  • Gordon Saxby 1444 posts 1855 karma points
    Feb 19, 2015 @ 12:39
    Gordon Saxby
    0

    BundleConfig:

    namespace ABC
    {
    using System.Web.Optimization;

    using ABC.Bundles;

    public class BundleConfig
    {
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));

    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.validate*"));

    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include("~/Scripts/modernizr-*"));

    bundles.Add(new StyleBundle("~/bundles/css").Include("~/Content/Site.css"));

    #region Foundation Bundles

    bundles.Add(Foundation.Scripts());
    #endregion
    }
    }
    }

    I have just checked again and ... if I view the page source and click any of the bundle links, it shows me the source. However, in Chrome Dev tools, it shows all bundles as "404". The page is definitely not getting the CSS or JS files.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 19, 2015 @ 12:45
    Dave Woestenborghs
    0

    Can you comment the line BundleTable.EnableOptimizations = true;

    This will always minify and bundle your css and ignoring the web.config debug attribute.

    Another option is to add your scripts / css line by line and see on which one it's failing. I had the bundling failing once on a syntax error.

    Dave

  • Gordon Saxby 1444 posts 1855 karma points
    Feb 19, 2015 @ 13:10
    Gordon Saxby
    0

    Oh, I thought "BundleTable.EnableOptimizations = true;" made it always bundle?! So, comment that out?

    The weird thing is that the bundle link works if I go there directly - i.e. paste it into a browser, but it doesn't load for the actual page (gives a 404).

    I am testing on Windows 7 & IIS - do I need to configure anything in IIS?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 19, 2015 @ 13:20
    Dave Woestenborghs
    0

    Do you have this behavior in all browsers or only in Chrome ?

    Dave

  • Gordon Saxby 1444 posts 1855 karma points
    Feb 19, 2015 @ 13:29
    Gordon Saxby
    0

    I have just checked it in IE v11 and it is the same.

    With debug set to true, I get this:

    href="/bundles/css" rel="stylesheet"/>

    Shouldn't it just output direct links to the css file(s)? Scrap that ... restarted IIS and it now does output the css link

  • Gordon Saxby 1444 posts 1855 karma points
    Feb 19, 2015 @ 14:54
    Gordon Saxby
    0

    Grrr, still won't work ... I think it's time to give up on bundling :-(

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 19, 2015 @ 16:23
    Dave Woestenborghs
    0

    Does it work when you are running in debug mode ?

    Dave

  • Gordon Saxby 1444 posts 1855 karma points
    Feb 19, 2015 @ 16:53
    Gordon Saxby
    0

    With debug set to true it outputs direct links to all individual files.

    With debug set to false, I get the correct (looking!) bundle links but the links return 404 (as shown by dev tools in Chrome, IE, etc). However, if I "view source" and click on any of the bundle links, it shows me the bundled file content.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 19, 2015 @ 16:56
    Dave Woestenborghs
    102

    Suddenly remember something. 

    You need to update your web.config for this to work :

     <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/bundles/" />

    Dave

  • Gordon Saxby 1444 posts 1855 karma points
    Feb 19, 2015 @ 17:11
    Gordon Saxby
    0

    Yes, that worked!!! :-)

  • Torben Rahbek Koch 4 posts 25 karma points
    Apr 13, 2015 @ 15:24
    Torben Rahbek Koch
    0

    Thanks a zillion, Dave!

  • Hywel Rees 56 posts 224 karma points
    Mar 14, 2016 @ 11:20
    Hywel Rees
    0

    Awesome.

Please Sign in or register to post replies

Write your reply to:

Draft