Add an Expires header on images, css and js files

Yslow is a very useful extension for firebug that gives you optimisation tips for your site. The performance grade is split into 13 different recommendations. If some of them like “Put js at the bottom” or “Make js and CSS external” are obvious in their meaning I had trouble to get find the solutions for the others.

On rule state “Add an Expires header”. When I can guess they are talking about the http header sent by the server when you request a file it did take me a long time to figure out what to do to please Yslow.

Here is the solution. To add Expires header to all your images, css and js files, which are not meant to be modified everyday follow this. First Open the .htaccess file on the root of your site or create one if you have got one. Then just copy and paste this rule:

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

That will add the previously stated header to all the file with matching extensions. You can change the expire data to a later date of course.

2 responses to “Add an Expires header on images, css and js files”

  1. Thomas

    Hi, just in case your server hasn’t got the module it’s better to enclose the tag with a …

    Greetings
    Tom

  2. Lovi

    Thank you wery much! That’s the solution I’m looking for.

Leave a Reply

Theme Forest ad
Wordpress Themes Collection ad
Woothemes

Poll

How do you start your WordPress plugins development projects?

View Results

Loading ... Loading ...