Optimizing headers for site speed

cache Today I had to do some tweaks to improve the loading speed of a site with a good amount of traffic and many relatively large photos on it. When you have a lot of static content, one of the easiest ways to improve the server’s performance is to fine-tune client-side caching.

We can do that by instructing browsers and proxies to cache our static content for a longer time. Of course, they are not obliged to follow these instructions, but it often helps ensure browsers don’t forget to store your content in their cache.

Hopefully, this should reduce the overall number of requests, making the server a bit more responsive for everyone.

If your site is running on Apache or a compatible server, the only thing you need to do is to create (or modify) a file named .htaccess in your web directory and add this snippet to it:


ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"

Leave a Reply

Your email address will not be published. Required fields are marked *

*