Leveraging browser caching

Here’s how to cache CSS / PNG files.

1. Use Expires caching headers 

i.e. rather than Cache-Control – see:

https://developers.google.com/speed/docs/best-practices/caching?hl=sv#LeverageBrowserCaching

2. If you’re using Apache these are set in the httpd.conf file:

e.g.  

<IfModule mod_expires.c>

    ExpiresActive On

    ExpiresDefault “access plus 10 days”

    ExpiresByType text/css “access plus 1 week”

    ExpiresByType text/plain “access plus 1 month”

    ExpiresByType image/gif “access plus 1 month”

    ExpiresByType image/png “access plus 1 month”

    ExpiresByType image/jpeg “access plus 1 month”

    ExpiresByType application/x-javascript “access plus 1 month”

    ExpiresByType application/javascript “access plus 1 week”

    ExpiresByType application/x-icon “access plus 1 year”

</IfModule>

http://css-tricks.com/snippets/htaccess/set-expires/

3. If you’re on a Dreamhost VPS the httpd.conf file is here:

/dh/apache2/apache2-ps<your-number>/etc/httpd.conf

To access it use:

su – <your-admin-user>

and restart with:

sudo /etc/init.d/httpd2 restart

4. And you can test how successful your updates were here:

http://tools.pingdom.com/fpt/

Leave a Reply

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