Link to home
Start Free TrialLog in
Avatar of singh101
singh101

asked on

How to Add Expires headers

What changes would I need to make to the httpd.conf file to add Expires headers to all html, html, images and css files and javascript files.

The static content (css, images and html files) hardly change so these I would like to set a date of at least 6 months.

However I have one javascript file out of 4 which is likely to change every 3 months. how can I set this so that if the date on the server is changed then the browser always requests the newer one else uses the one in the cache.

The other 3 javascript files I would like to set a date in 1 year.

Thanks in Advance.
Avatar of singh101
singh101

ASKER

By the wat we are using Apache 1.3
Avatar of David S.
You can use mod_expires (http://httpd.apache.org/docs/1.3/mod/mod_expires.html) for that.

Try this:
ExpiresByType text/html "modification plus 6 months"
ExpiresByType text/css "modification plus 6 months"
ExpiresByType image/jpeg "modification plus 6 months"
ExpiresByType image/png "modification plus 6 months"
ExpiresByType image/gif "modification plus 6 months"

<FilesMatch "\.js">
ExpiresByType application/x-javascript "modification plus 12 months"
</FilesMatch>
<FilesMatch "special\.js">
ExpiresByType application/x-javascript "modification plus 3 months"
</FilesMatch>

Open in new window

Thanks, if for example the date this javascript file was modified on the server is 05/04/2010. I then access the file on the 07/04/2010. I wil get the this file downloaded from the server into my browser cache. Suppose now the file gets modified on the 08/04/2010.

I then access this file - will this give me the new file on the server or will it be served from the cache?
ASKER CERTIFIED SOLUTION
Avatar of David S.
David S.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial