Speed up your sites with a htaccess rule hack
29 Dec 2010Paste this into your root .htaccess file to speed up your sites.
It works by:
- gziping raw text files (compressing them).
- Removing Etag headers, they force the browser hash each cached file it accesses. Instead we rely on a faster method, expires headers.
- Adds expire headers tell the browser to cache content until it expires. Most servers don’t recognise the correct javascript MIME type, so we tell it to find them by .js files instead.
# gzip foles AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css <FilesMatch "\\.(js|css|html|htm|php|xml)$"> SetOutputFilter DEFLATE </FilesMatch> # etags Header unset ETag FileETag None # expires (js has special case:) <FilesMatch "\.(js)$"> ExpiresDefault A29030400 </FilesMatch> <FilesMatch "\.(ico)$"> ExpiresDefault A29030400 </FilesMatch> <IfModule mod_expires.c> ExpiresActive On ExpiresByType text/html "access plus 1 seconds" ExpiresByType image/gif "access plus 2 years" ExpiresByType image/jpeg "access plus 2 years" ExpiresByType image/png "access plus 2 years" ExpiresByType text/css "access plus 2 years" ExpiresByType text/javascript "access plus 2 years" ExpiresByType application/x-javascript "access plus 2 years" </IfModule>
Before:
After:
The above data is for this site. That’s almost a 290% increase in speed!
Primed Cache before:
After:
Revisiting the site is even better, we have 4 times less data. I highly recommend YSlow by yahoo!, it allows you to make critical optimisations to your site. Remember every second counts when loading sites.



