.htaccess is a magic file that tells apache to how to serve files in a directory. It is the most common also the best way to speed up your website.
One of the most important factor in page loading speed, is that everytime a user enters your site, browser loads every image, script and stylesheet again. To prevent this behaviour, We can tell browser to cache static files for future use.
# Enable browser cache for images and styles <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(.gz)?$"> Header set Expires "Thu, 15 Apr 2014 20:00:00 GMT" Header unset ETag FileETag None </FilesMatch>
You must change expiring date to a far future date. This way, until that day comes, and of course if user doesn’t clear cache manually static files won’t be downloaded again. ETag’s must be disabled for caching to work successfully. You can debug your file header information using AskApache’s HTTP Header Debugger. It will show you if your file has an expiry date or not.
You should have mod_deflate module installed and enabled for gzip compression to work. Most of the web hosting companies allow you to enable/disable apache modules, so you can check it on your hosting control panel. Even if you don’t know, i recommend adding the code, because code will check if it works. If it doesn’t, apache will simply ignore those lines.
Today, page loading speed is one of the most important keys to a successful website. Most of the visitors leave the website because it is slow. If you want to make your website faster, .htaccess is the most important key. I also recommend serving your static files from a cookie free domain. But that’s another story. Cheers!