July 16, 2010

Page speed: optimize caching

by Karine in Intermediate with no response

Again, the website speed optimization freak in me speaks ! Maybe Page Speed is telling you to leverage browser caching? Or YSlow to configure entity tags? So how do we do it ? It's pretty simple, open your .htaccess file (or create it if you don't have one) and add these lines :

Turn off unused entity tags

FileETag none

Now we have to add an file type for favicons

AddType image/x-icon .ico

Icons, images, flash objects are things that don't change often, so we can cache them for 2 months (or even more)

<FilesMatch "\.(ico|jpg|jpeg|png|gif|swf)$">
ExpiresActive on
ExpiresDefault "access plus 2 months"
</FilesMatch>

On the other hand, JavaScript and CSS files change often, so let's cache them for 3 days only. If you don't make changes to your design often, you can set this value longer.

<FilesMatch "\.(js|css)$">
ExpiresActive on
ExpiresDefault "access plus 3 days"
</FilesMatch>

In the end, you have this in your .htaccess file !

FileETag none
AddType image/x-icon .ico
<FilesMatch "\.(ico|jpg|jpeg|png|gif|swf)$">
ExpiresActive on
ExpiresDefault "access plus 2 months"
</FilesMatch>
<FilesMatch "\.(js|css)$">
ExpiresActive on
ExpiresDefault "access plus 3 days"
</FilesMatch>

Tags

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

↑ Back to Top