Copied to clipboard

Flag this post as spam?

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


  • nickornotto 403 posts 907 karma points
    Aug 09, 2017 @ 12:45
    nickornotto
    0

    BundleConfig routing not rendering all files after publishing live

    I have a routeconfig set up for a microsite within umbraco and am using BundleConfig to get my styles and scripts.

    I made everything working on my local site however when I published everything live the bootstrap.css does not render in html head while the other custom css file renders.

    cshtml declaration:

    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/bootstrap")
    

    BundleConfig content:

    public class BundleConfig
    {
        // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            //bundles.IgnoreList.Clear();
    
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
    
            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));
    
            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));
    
            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js"
                      //,"~/Scripts/respond.js"
                      ));
    
            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/css/style.supplier.css",
                      "~/Content/css/bootstrap.css"));
        }
    }
    

    Localhost head:

    <link href="/Content/css/bootstrap.css" rel="stylesheet"/>
    <link href="/Content/css/style.supplier.css" rel="stylesheet"/>
    <script src="/Scripts/modernizr-2.6.2.js"></script>
    <script src="/Scripts/jquery-1.10.2.js"></script>
    <script src="/Scripts/jquery.validate.js"></script>
    <script src="/Scripts/jquery.validate.unobtrusive.js"></script>
    <script src="/Scripts/bootstrap.js"></script>
    

    Live head:

    <link href="/Content/css/style.supplier.css" rel="stylesheet"/>
    <script src="/Scripts/modernizr-2.6.2.js"></script>
    <script src="/Scripts/jquery-1.10.2.js"></script>
    <script src="/Scripts/jquery.validate.js"></script>
    <script src="/Scripts/jquery.validate.unobtrusive.js"></script>
    <script src="/Scripts/bootstrap.js"></script>
    

    As you can see only

    <link href="/Content/css/bootstrap.css" rel="stylesheet"/>
    

    declaration is missing in live source.

    I checked and the file exists in the correct location on live. I also checked in other browsers.

    Any ideas while the link may not be rendering?

  • John Bergman 483 posts 1132 karma points
    Aug 14, 2017 @ 16:34
    John Bergman
    0

    I believe you need to make this changes to your web.config

    Inside the appSettings section, add "~/bundles"

    <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/hangfire,~/bundles" />
    
  • nickornotto 403 posts 907 karma points
    Aug 15, 2017 @ 10:09
    nickornotto
    0

    No, it's always cutting first bundle file, eg. if I do this:

    bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/css/blank.css",
                      "~/Content/css/style.supplier.css",
                      "~/Content/css/bootstrap.css"));
    

    blank.css will not render in the source while the two other files will render.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 15, 2017 @ 11:21
    Dan Diplo
    1

    In my experience missing files always means you have the path wrong. It will silently disclude files it cannot find on disk.

  • nickornotto 403 posts 907 karma points
    Aug 15, 2017 @ 11:25
    nickornotto
    0

    I thought so too but when "~/Content/css/bootstrap.css" goes as first item of Include then it does not render in the page source.

    If it comes as any of the following items - it does render on the page and render correct link.

    So - in essence the position matters - and not the path is wrong.

    Same with any other path - if I put any other path as first item then it does not render while the following items always render.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 15, 2017 @ 11:31
    Dan Diplo
    0

    Just to be clear about your expectations for this:

    bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/css/blank.css",
                      "~/Content/css/style.supplier.css",
                      "~/Content/css/bootstrap.css"));
    

    This will create one combined, minified CSS file. So all three CSS files will be combined into one file and minified. So in live you would only ever expect to have one CSS file, but it should contain all three files combined. Have you checked the source of the combined file to definitely ascertain the first file hasn't been added?

  • nickornotto 403 posts 907 karma points
    Aug 15, 2017 @ 12:05
    nickornotto
    0

    And what is supposed to be the path/ filename of the combined file?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 15, 2017 @ 12:14
    Dan Diplo
    0

    In the above cass it would be ~/Content/css I believe. The path is the first parameter.

    But by convention I would change it to ~/bundles/Content/css

    I would then do as John suggests and add ~/bundles to the umbracoReservedPaths section in web.config to ensure Umbraco doesn't intercept these paths.

  • nickornotto 403 posts 907 karma points
    Aug 15, 2017 @ 12:43
    nickornotto
    0

    What would be the minified filename then?

    However the problem is not that the path is not rendered in the source - I believe it's only a symptom.

    The problem is that the classes from this file are not available on the live site - I can only assume that they are not thus included in the minified file.

    Since it doesn't happen on my local (styles are correct) only on live (styles are missing) I can also assume that the minified file should exist on my local - I can't see anything new under Content/css though and the style paths are rendered in the page source.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 15, 2017 @ 14:09
    Dan Diplo
    0

    I'm not sure why it's not there, but the generated files are not physical files - they only exist in memory.

    I'd read: https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification

  • John Bergman 483 posts 1132 karma points
    Aug 16, 2017 @ 04:47
    John Bergman
    0

    If you change the site to run in Debug mode, bundling will not combine the files, but instead render the paths, I would do that, and use a tool like fiddler to see if you have any 404 errors.

Please Sign in or register to post replies

Write your reply to:

Draft