Browser Caching

Browsers cache the files they download. This means they don’t have to load your CSS or jQuery scripts every time you go to a new page. This speeds things up a lot but if you have files that don’t change much it’s worth extendng the time these files are cached.

The way to do this is to add some instructions to your .htaccess. You can get to .htaccess using FTP. FTP is set up is your hosting control panel.

Download and open .htaccess in a text editor and add the following:

<filesMatch “.(css|jpg|jpeg|png|gif|js|ico|ttf)$”>
Header set Cache-Control “max-age=2628000, public”
</filesMatch>

<FilesMatch “\.(js|css|xml|gz)$”>
Header append Vary: Accept-Encoding
</FilesMatch>

ExpiresActive on

ExpiresByType image/jpg “access plus 60 days”
ExpiresByType image/png “access plus 60 days”
ExpiresByType image/gif “access plus 60 days”
ExpiresByType image/jpeg “access plus 60 days”
ExpiresByType text/css “access plus 1 days”
ExpiresByType image/x-icon “access plus 1 month”
ExpiresByType application/pdf “access plus 1 month”
ExpiresByType audio/x-wav “access plus 1 month”
ExpiresByType audio/mpeg “access plus 1 month”
ExpiresByType video/mpeg “access plus 1 month”
ExpiresByType video/mp4 “access plus 1 month”
ExpiresByType video/quicktime “access plus 1 month”
ExpiresByType video/x-ms-wmv “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access 1 month”
ExpiresByType text/javascript “access plus 1 week”
ExpiresByType application/x-javascript “access plus 1 week”
ExpiresByType application/javascript “access plus 1 week”
ExpiresDefault “access plus 1 days”

Save the file (don’t change the filename) and upload. Make sure the site still works and you should be all done.

Web Analytics