How CSS and JavaScript minification works in Kentico

   —   
Many clients think that minification is not working correctly because when they try open the CSS/JS file with minification setting enabled; it’s exactly the same so they don’t see any “optimizations”.
The reason is that if you try to open the CSS file in the browser, it’s directly opened from the original source file. The minification is handled on the Kentico (server) side on the page request, it's just how the file is delivered to the browser, it doesn't affect the original file. Also, the important fact is that minified files are only CSS and JS files uploaded via CMS Site Manager.
If the final link to the CSS file is /CMSPages/GetResource.ashx?stylesheetname=stylesheet_file then the CSS minification is working properly, as the link would be outputted as /CMSPages/GetCSS.aspx?stylesheetname=stylesheet_file if the minification was either disabled or not working correctly.         

For example: the response header with CSS minification enabled for the CorporateSite stylesheet is:
HTTP/1.1 200 OK Cache-Control: public, must-revalidate Content-Type: text/css Content-Encoding: gzip Expires: Wed, 24 Jul 2013 17:48:29 GMT Last-Modified: Tue, 11 Sep 2012 10:01:13 GMT ETag: cssstylesheet|1f2effc8-8c9c-41d5-9105-2e474ab1a0e8 Vary: Accept-Encoding Server: Microsoft-IIS/7.5 Content-Disposition: attachment; filename=CorporateSite.css X-AspNet-Version: 4.0.30319 X-Frame-Options: SAMEORIGIN X-Powered-By: ASP.NET Date: Wed, 24 Jul 2013 17:48:29 GMT Content-Length: 21600

while the with CSS minification disabled it returns:
HTTP/1.1 200 OK Cache-Control: public, must-revalidate Content-Type: text/css Content-Encoding: gzip Expires: Wed, 24 Jul 2013 17:49:40 GMT Last-Modified: Tue, 11 Sep 2012 10:01:13 GMT ETag: cssstylesheet|1f2effc8-8c9c-41d5-9105-2e474ab1a0e8 Vary: Accept-Encoding Server: Microsoft-IIS/7.5 Content-Disposition: attachment; filename=CorporateSite.css X-AspNet-Version: 4.0.30319 X-Frame-Options: SAMEORIGIN X-Powered-By: ASP.NET Date: Wed, 24 Jul 2013 17:49:40 GMT Content-Length: 25860

as you can see, the difference could be seen in the returned file size 21.6KB versus 25.86KB.
-md-


See also:
Code minification and compression

Applies to: Kentico CMS 7.x
Share this article on   LinkedIn

Martin Danko

Let me guide you on your journey of success. I will show you how to optimize your content production with Kentico Draft. Check out www.kenticocloud.com