0

When I publish my MVC web app I can see that the published location gets the original js and css files, it does get minified when I run it (I can see it in view source)

This is what I'm doing:

        BundleTable.EnableOptimizations = true;

        bundles.UseCdn = false;
        var cssTransformer = new StyleTransformer();
        var jsTransformer = new ScriptTransformer();
        var nullOrderer = new NullOrderer();

        var cssBundle = new StyleBundle("~/bundles/css");
        cssBundle.Include("~/Content/Site.less", "~/Content/bootstrap/bootstrap.less");
        cssBundle.Transforms.Add(cssTransformer);
        cssBundle.Transforms.Add(new CssMinify());
        cssBundle.Orderer = nullOrderer;
        bundles.Add(cssBundle);

        var sampleCssBundle = new StyleBundle("~/bundles/sampleCss");
        sampleCssBundle.Include("~/Content/sample.css");
        sampleCssBundle.Transforms.Add(cssTransformer);
        sampleCssBundle.Transforms.Add(new CssMinify());
        sampleCssBundle.Orderer = nullOrderer;
        bundles.Add(sampleCssBundle);

        var sampleJsBundle = new ScriptBundle("~/bundles/sampleJs");
        sampleJsBundle.Include("~/Scripts/sample.js");
        sampleJsBundle.Transforms.Add(jsTransformer);
        sampleJsBundle.Transforms.Add(new JsMinify());
        sampleJsBundle.Orderer = nullOrderer;
        bundles.Add(sampleJsBundle);
  1. will I get a better performance if I deploy a minified version of the files to the published location? (for example: myFile.min.js and myFile.min.css)

  2. is there a native way to generate the files in Visual Studio so I can publish it minified? (I could view each minified file and save it as myFile.min but I like to have an automated way to do it)

Thanks in advance.

Yovav
  • 2,557
  • 2
  • 32
  • 53

1 Answers1

1

I'm always excited to see someone tuning their website performance!

1) As long as you are referencing the bundles (and not the published files), publishing minified files will have negligible impact. The bundling system reads the files only once and caches a minified and bundled version in memory. The resulting bundle is identified with a hash that is included in the page and allows browser and proxy caching of the bundle. When your published files change, the bundle will be updated and the page will use the new bundle hash.

This answer has additional information on caching.

If you are interested in automating the "first request" explore Application Initialization

2) The Web Essentials extension by Mads Kristensen has minification support for CSS and JavaScript. As of Visual Studio 2013 Update 4 there is no built-in tooling that would create minified files.

Community
  • 1
  • 1
Matthew K
  • 973
  • 6
  • 21
  • I would love to find more information on how the bundles are being cached... do you know how can the bundles be invalidated in case I have some CSS or Javascript update that I need to push? – Yovav Jan 01 '15 at 01:54
  • 1
    using Web Essentials 2013 is truly an awesome thing for any developer- the below url helped me in understanding the minification of JS and CSS files in details, Hope is helps somebody too- https://cann0nf0dder.wordpress.com/2014/04/08/visual-studio-web-essentials-minified-and-source-map-files/ – Manik Arora Jan 23 '15 at 06:32