tags:

views:

148

answers:

2

I'm doing a little bit of ajax where I get a static html file that is actually changed on the disk from time to time. Of course IE has a problem where it wants to help out by caching the file which I don't want. I know how to fix this when grabbing a dynamic file: you just change the header in the dynamic file. But how do I do this for the static html file? Note that I am using apache.

Thanks

+3  A: 

At Apache level you can setup the expiry date of the document using the mod_expires module.

From the documentation:

This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.

These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source.

More details at http://httpd.apache.org/docs/2.0/mod/mod_expires.html

Marcel Tjandraatmadja
+1  A: 

If you can use mod_expires as Marcel suggested, you can always append a random request parameter.

For example, instead of requesting static_file.html you can request static_file.html?_=1231231231 and change that request parameter every time.

jQuery has a really simple way of doing this:

$.ajax({cache: false, url: static_file.html});
grammar31