Speed Tips: Add Future Expires Headers
« Firefox, Firebug, and yslow are REQUIREDSpeed Tips: Turn Off ETags »
A first-time visitor to your page will make several HTTP requests to download all your sites files, but using the Expires header you make those files cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers should be used on all components including scripts, stylesheets, and Flash components.
Easy Apache Speed Tips Articles
Keep in mind, if you use a far future Expires header you have to change the component’s filename whenever the file changes.
This goes in your root .htaccess file but if you have access to httpd.conf that is better.
This code uses the FilesMatch directive and the Header directive to add Future Expires Headers to certain files.
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" </FilesMatch>
« Firefox, Firebug, and yslow are REQUIRED
Speed Tips: Turn Off ETags »
Tags: Headers, htaccess, optimization, YSlow
Please consider donating to support active development of the free software and articles here.![]()
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect. Tim Berners-Lee
I have implemented this code in the htaccess of my Wordpress blog, however, I am still getting an F from YSlow for not having expires headers on the adsense code on my site. Is there any way to remedy that, or is that not really having any significant effect on my loading speed despite the poor score? Thanks.
Thanks for the great content. I came across your site as I was trying to fix a caching problem on one of my websites. I’m a bit of a novice when it comes to caching and did a lot of damage to my site this past week experimenting with far future expires header.
In your post, you say
Keep in mind, if you use a far future Expires header you have to change the component’s filename whenever the file changes.
I would be very grateful if you could point me in the right direction as to what code I should include in my .htaccess file to fix this problem.
After I made this initial change, I lost my enter header section of my website and it also screwed up the rest of my page template.
Thanks in advance for your help!
Hi,
i just would like to know one thing. if you combine using multiple subdomain to serve images and script, where would put your .htaccess file that hold the cache control header, future expire header and all this for images.
do you put it in your main domain root or in the subdomains root where you have images and script?
thanks
julien
Hello, when l add this to my .htaccess it crashes my site (returns 404) … any idea why?
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
That middle part actually gives me 500 error. is there another way?
It might be helpful for readers to also mention that you are using Yahoo’s Yslow addon for the Firebug extension to get the analysis presented in the screen shots (without/with).
YSlow for Firebug
http://developer.yahoo.com/yslow/
It's very simple - you read the protocol and write the code. -Bill Joy
HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C | TLDP | WAI | DISA | ICSI | GIAC | SANS RR | GHOST | DEFCON | NIST | DHS CYBER | NIST | .:: Phrack Magazine ::.
↑ TOPExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. HTTPD based on NCSA HTTPd
Please can you explain me how to setup this expire header to the
httpd.conffile. I have access tohttpd.confthrough ssh.