0

I'm looking at using web optimizations to minify and bundle js and css so I spun up a new vanilla mvc4 internet application in visual studio, set RELEASE mode and hit F5.

It doesn't seem to behave the way I was expecting. When I view source I see.

    <link href="/Content/site.css" rel="stylesheet"/>
    <script src="/Scripts/modernizr-2.6.2.js"></script>

I was expecting to see a cache buster ?v=kjzshd3289sjhdf98je3l.

Also the scripts and css are not mininfied.

chrisp_68
  • 1,731
  • 23
  • 41

1 Answers1

0

In your Application_Start() in Global.asax try this code:

#if DEBUG
            BundleTable.EnableOptimizations = false;
#else
            BundleTable.EnableOptimizations = true;
#endif
Artyom Neustroev
  • 8,627
  • 5
  • 33
  • 57
  • Thanks for the answer. sure, that works, but I was under the impression this was handled by the build configuration. When I view source, I now see the cache buster but viewing the source its not minified. http://localhost:49941/Content/css?v=WMr-pvK-ldSbNXHT-cT0d9QF2pqi7sqz_4MtKl04wlw1 – chrisp_68 Jun 04 '13 at 08:38
  • `EnableOptimizations` overrides compilation element in the Web.config, so it is probably set to "debug" anyways. How do you add your files to bundle? Do .js files remain untouched too? – Artyom Neustroev Jun 04 '13 at 08:44
  • js is included like this: @Scripts.Render("~/bundles/modernizr") and is minified css is rendered like this: @Styles.Render("~/Content/css") and is not minified – chrisp_68 Jun 04 '13 at 09:40
  • This is how they are rendered. I'm talking about `new Bundle("~/somepath").Include("~/SomePath")`. – Artyom Neustroev Jun 04 '13 at 09:42
  • Ah ok. I have not changed the vanilla code from the VS template so it is still that same code in (I cant paste it all here) public static void RegisterBundles(BundleCollection bundles) {.... bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));......} – chrisp_68 Jun 04 '13 at 10:45
  • How do you expect your CSS to be minified? Because with such declaration it _IS_ minified. – Artyom Neustroev Jun 04 '13 at 11:21