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.
singh101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

singh101Author Commented:
By the wat we are using Apache 1.3
0
David S.Commented:
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

0
singh101Author Commented:
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?
0
David S.Commented:
I was hoping another expert with more experience in this area might reply, but it seems unlikely now.

Anyway, my understanding is that if the file is modified before it's set to expire in the cache, the cached copy will be used unless a user forces the browser to fetch a fresh copy (by clearing their cache or doing a hard refresh).  So if the file may change, don't set the expires header to be too far into the future.


Upon rereading your original question, I see the following:

>  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.

Perhaps it would be helpful to make sure that your server is configured to use ETags. Basically what they do is allow the browser to ask the server to send a new copy only if the file hasn't been changed.

http://en.wikipedia.org/wiki/HTTP_ETag
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.