1
votes

I've been using ASP.NET bundling and minification with the nugget package Microsoft.AspNet.Web.Optimization.

I noticed yesterday that the majority of my bundle files no longer have the v query string parameter to the exception of one of them:

/Sgc.Web/bundles/css/JQueryUI

/Sgc.Web/bundles/css/DefaultPage

/Sgc.Web/bundles/js/Menu

/Sgc.Web/bundles/js/DefaultPage

/Sgc.Web/bundles/js/ReportOutputs

/Sgc.Web/bundles/js/UnderscoreBackbone?v=4YsZ6DBVserabs64GE87Ua4d51aeg0D1wXHWNe3E6NU1

The JS bundle that still has the query string always keeps on producing different v param values after I do changes on it (as expected). However the remaining bundles (either css or js) when I make changes on their css or js files they do incorporate those changes but do not produce a v param value any more.

The C# code to perform the bundling:

// -- create and add CSS bundles without minification
  BundleTable.EnableOptimizations = true;

  bundles.Add(new Bundle("~/bundles/css/JQueryUI").Include(
               "~/Styles/Gui/jquery-ui-1.10.4-custom.css",
               "~/Styles/Gui/jquery-ui-custom.css",
               "~/Styles/Gui/jquery.ui.combogrid.css"));

  bundles.Add(new Bundle("~/bundles/css/DefaultPage").Include(
               "~/Styles/Default.css",
               "~/Content/toastr.min.css"));   

  // -- create and add JS bundles without minification
  bundles.Add(new Bundle("~/bundles/js/DefaultPage").Include(
                "~/Scripts/Defaults.js",
                "~/Scripts/toastr.min.js"));

  bundles.Add(new Bundle("~/bundles/js/Menu").Include(
                "~/Scripts/Gui/Menus/SuperFish/jquery.hoverIntent.r7.min.js",
                "~/Scripts/Gui/Menus/SuperFish/superfish1_7_4.min.js",
                "~/Scripts/Gui/Menus/SuperFish/factory.js"));

  bundles.Add(new Bundle("~/bundles/js/UnderscoreBackbone").Include(
                "~/Scripts/underscore.min.js",
                "~/Scripts/backbone.min.js"));

  bundles.Add(new Bundle("~/bundles/js/ReportOutputs").Include(
                "~/Scripts/Gui/jquery-visibility.js",
                "~/Scripts/UserControls/ReportOutputs.js"));

  //-- if in Release mode, then minify all the bundles
  if (!System.Web.HttpContext.Current.IsDebuggingEnabled)
  {
      CssMinify cssMinify = new CssMinify();
      JsMinify jsMinify = new JsMinify();

      foreach (Bundle bundle in bundles)
      {
          if (bundle.Path.Contains("/js"))
          {
              bundle.Transforms.Add(jsMinify);
          }
          else
          {
              bundle.Transforms.Add(cssMinify);
          }
      }

As can be seen from above I'm building the bundle with the Bundle super class instead of the StyleBundle or ScriptBundle sub classes. However I also tried to make bundles with these 2 subclasses and the result was the same: all bundles still didn't had v param to the exception of the UnderscoreBackbone bundle. As far as I know there is no difference in the way the UnderscoreBackbone bundle is being made and the remaining bundles.

I'm using,

  • Windows 8.1
  • VS Premium 2013 with Update 1
  • Microsoft.AspNet.Web.Optimization 1.1.3
  • WebGrease 1.6.0
  • Microsoft.Web.Infrastructure 1.0.0.0
  • Json.NET (Newtonsoft.Json) 6.0.1
  • ANTLRv3 3.5.0.2

Does anyone ever faced this kind of problem before or any hint as to where can I look for a solution to it ?

Thanks in advance,

MggLp

1
Try getting rid of the if (!System.Web.HttpContext.Current.IsDebuggingEnabled)... and replace with bundles.Add(new ScriptBundle and bundles.Add(new StyleBundle. Also ensure any bundle name also doesn't have the same name as a directory. It's safer to use ~/bundles/bundleName to ensure no conflict. And your src names don't seem to match up with your bundle names. Please show how you are referencing bundles.MikeSmithDev
I did some tests with the IsDebuggingEnabled if commented + using StyleBundle and ScriptBundle but nothing changed in relation to the description made above. Also I reinstalled new versions of the nugget packages Microsoft.AspNet.Web.Optimization, WebGrease, Json.NET and ANTLRv3 but no luck either.Miguel Goncalves
What do you do to render your bundles? For ScriptBundle System.Web.Optimization.Scripts.Render("~/bundles/js/DefaultPage"), For StyleBundle System.Web.Optimization.Styles.Render("~/bundles/css/JQueryUI"). The render method will generate the correct html tags and include v. However, Bundle doesn't have Render , so I guess you use "Path" to get the URI?Roman Mik
Please check if the file path is correct. This could happen if the file is not loaded. Press F12 and see in developer tools if the file is loaded..Adithya Kumaranchath

1 Answers

0
votes

Sometimes, in views, we might be doing something like -

Scripts.Render("/bundles/js/Default‌​Page")

but the correct syntax to get hash -

Scripts.Render("~/bundles/js/Default‌​Page").

It might be the matter of absolute and relative path. Using ~ we can get the querystring for the bundled files.