Diem snippets syndication

Improve performances: gzip assets

January 19, 2010 by Thibault D

This snippet will only work with apache2 servers.

Problem

Bandwidth has a cost, and performances matters.

By default, Diem minifies and combines all your javascript and stylesheet files. This reduces dramatically the number of requests required to display a page.

But we can go even farther.
You can enable gzip compression for javacript and stylesheet files. It reduces their weight by three to four times.

Enable gzip compression

Just change an option on Diem javascript and stylesheet compressors to make them produce gziped files.
config/dm/services.yml

parameters:  
  
  javascript_compressor.options:    
    gz_compression: true  
  
  stylesheet_compressor.options:    
    gz_compression: true  

Forward assets requests

Now, we will tell apache to forward requests to a .css or .js to the gzipped file, if any.
web/.htaccess, uncomment the lines between
# SEND GZIPPED CONTENT TO COMPATIBLE BROWSERS
and
# END GZIPPED CONTENT

You should now have:

  # SEND GZIPPED CONTENT TO COMPATIBLE BROWSERS  
  RemoveType .gz  
  RemoveOutputFilter .css .js  
  AddEncoding x-gzip .gz  
  AddType "text/css;charset=utf-8" .css  
  AddType "text/javascript;charset=utf-8" .js  
  RewriteCond %{HTTP:Accept-Encoding} gzip  
  RewriteCond %{REQUEST_FILENAME}.gz -f  
  RewriteRule ^(.*)$ $1.gz [L,QSA]  
  # END GZIPPED CONTENT  

Try it

Open a page of your website and inspect requests with firebug. The server now sends gzipped assets, and load time is reduced.

This tip will not work on all servers, depending on apache configuration.

Add a comment

Comments

  • gohpwxaoJuly 3, 2013 1:17 AM

    <img>http://i.jootix.com/t/Jootix--c18dca3bcd_big.jpg </img>
    и Здравствуйте. 7 дней назад мне поставили укол &quot;кардиомин&quot; в левую ягодицу в этот же день образовался синяк сейчас на этом месте образовалась внутренняя шишка <a href=http://greenfree.ru/xiru/66015-chto-delat.html>что делать????</a>

Fork Diem on GitHub