Archive

Posts Tagged ‘webiste performance’

Speed up website performance with mod_deflate compression via .htaccess

May 18th, 2010

The loading time of a website gets a lot of attention these days, at least since google said, that the loading speed is a factor for the ranking position. With compression of text files (CSS, HTML, JS) you can speed up the performance easily.

If the site is hosted on an Apache 2 webserver, there is an easy to add compression to your existing files without modifying or wrapping them – the only requirement is that Apache is compiled with mod_deflate (which should be standard on quality webhosting providers).

Simply add the following snippet to your .htaccess file:

# BEGIN Gzip
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|gif|jpeg|flv|swf)$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48, the above regex won’t work. You can use the following
# workaround (comment the above line and uncomment the below line) to get the desired effect:
# BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html


# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary

</IfModule>
# END Gzip

The “BrowserMatch” should prevent compression for older Browsers (inluding Internet Explorer), because there are issues with javascript compression (but it seems, that only certain versions of IE 6 are concerned…)

admin Programming , ,