Deliver gzipped content with htaccess and precompressed files To get a page which loads fast it's possible to use gzip to deliver the files to the client.
1st we need to compress these files: logon to your server via SSH or something similar, browse to the directory which contains the file(s) to compress gzip -c filename.ext > filename.ext.gz now you got a file with the following scheme: blabla.css.gz which has the same content as before, but should be significant smaller now. The 2nd step is to create a file named .htaccess (note the . before htaccess) in this file write the following RewriteEngine On RewriteBase / RewriteCond %{HTTP:Accept-Encoding} .*gzip.* RewriteRule ^/(.*)\.js$ /$1.js.gz [L] RewriteRule ^/(.*)\.css$ /$1.css.gz [L] AddEncoding x-gzip text.gz
Save it in the directory where the .gz file(s) from before are stored. If someone which has a gzip-capable browser (90+% support it) now accesses that file, the amount of data to transfer is less than before. For example a javascript-file with around 80kB before now has 20kB, which is only 25% of the original file, woohoo. Have Fun!
Credits: http://www.alinki.com/de/blog/archives/27
|