Doug Chamberlain
Doug Chamberlain

Reputation: 11351

setting debug='false' in web.config causes bundling to fail

When I change to run without debugging my bundling does not included the correct path in the html. it is dropping off the file name.

using System.Web;
using System.Web.Optimization;

namespace Search
{
    public class BundleConfig
    {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.UseCdn = true;

            var jqueryuiCdnPath = "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/jquery-ui.min.js";
            var knockoutCdnPath = "http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js";
            var modernizerCdnPath = "";

            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js",
                        "~/Scripts/jquery.printPage.js"
                        ));

            bundles.Add(new ScriptBundle("~/bundles/jqueryui", jqueryuiCdnPath).Include(
                        "~/Scripts/jquery-ui-{version}.custom.js"));

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

            bundles.Add(new ScriptBundle("~/bundles/knockout", knockoutCdnPath).Include(
                "~/Scripts/knockout-2.1.0.debug.js"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/scpa").Include(
            "~/Scripts/scpa.js"));


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


            bundles.Add(new StyleBundle("~/Content/themes/redmond").Include(
                        "~/Content/themes/redmond/jquery-ui-{version}.custom.css"));
        }
    }
}

These lines in my _layout.cshtml

    @Styles.Render("~/content/themes/redmond")
    @Styles.Render("~/content/css")

Generate the following html with debugging enabled

<link href="/Content/themes/redmond/jquery-ui-1.10.3.custom.css" rel="stylesheet"/>
<link href="/Content/NewSite.css" rel="stylesheet"/>
<link href="/Content/PagedList.css" rel="stylesheet"/>

however with debugging off this is generated

<link href="/content/themes/redmond?v=vAH9QfqxdFYSzS_GtpWa8fGJ5s-xvZ9vhODh9AGxIbo1" rel="stylesheet"/>
<link href="/content/css?v=3o7zDFviiGqrSMyW4LTNH-J9tRGdIoONnnh_FMEm4Mg1" rel="stylesheet"/>

Upvotes: 0

Views: 2190

Answers (1)

MikeSmithDev
MikeSmithDev

Reputation: 15797

That is how it is supposed to be generated.

Though your first bundle probably isn't working -- You can't give a bundle name the same name as an existing folder. Rename the second StyleBundle, like:

bundles.Add(new StyleBundle("~/Content/cssRedmond").Include(...

because the link it generates will work because it doesn't conflict with another folder:

<link href="/content/cssRedmond?v=..."  //This is OK
<link href="/content/themes/redmond?v=..." //Not OK. Conflicts with folder

Upvotes: 8

Related Questions