[development] preventing browser cache

David Metzler metzler.dl at gmail.com
Fri Dec 10 00:57:23 UTC 2010


WE use this technique to stop IE from stubbornly caching swf files, etc. But if you don't have control of the URL that the java applet references, then you won't likely have much luck.  The reason that this works is because it makes the urls different, so it doesn't see the cached version as the same fie. 

Rather than a random character, try including the file modification time so that it caches when it should and doesn't when it shouldn't. Something like: 

file.xml?ts=l12341242421

the number wold be the unix time stamp of the file modification time or the current timestamp if you want it to load every page. 



On Dec 9, 2010, at 2:17 PM, Blake Senftner wrote:

> Thanks for the tip Mike. These are files on disk. 
> 
> Sincerely,
> -Blake
> bsenftner at earthlink.net
> www.BlakeSenftner.com
> www.MissingUbercartManual.com
> 
> On Dec 9, 2010, at 1:09 PM, Michael Prasuhn wrote:
> 
>> That is only needed with actual files on disk, if your XML is returned from a Drupal menu callback, it's cache-expire headers should be set far in the past to prevent caching. Check this out with curl -v to see what's going on.
>> 
>> -Mike
>> __________________
>> Michael Prasuhn
>> 503.512.0822 office
>> mike at mikeyp.net
>> http://mikeyp.net
>> 
>> On Dec 9, 2010, at 1:05 PM, Blake Senftner wrote:
>> 
>>> I'm finding that I need to implement a browser cache prevention scheme for dynamic content I am generating.
>>> 
>>> My use case: user supplied info gets converted into XML and loaded by a java applet on the same page.
>>> 
>>> I'm seeing the java applet load cached versions of the data, and I want to prevent this. 
>>> 
>>> I don't have the ability to modify the java applet, and it always loads it's XML from the same filename. 
>>> 
>>> I'm thinking about using the same technique that I see Drupal use for javascript files, where the src attribute's file url has a fake query string at the end, something like "/misc/drupal.js?5" , where the "?5" is the fake query string.
>>> 
>>> It's my understanding that this prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content. 
>>> 
>>> Is my understanding correct? I've not done this before. Is it simply a matter of placing a single random character after the question mark? 
>>> To anyone that has implemented a scheme such as this: any pitfalls I should be aware? 
>>> 
>>> Sincerely,
>>> -Blake
>>> bsenftner at earthlink.net
>>> www.BlakeSenftner.com
>>> www.MissingUbercartManual.com
>>> 
>> 
> 



More information about the development mailing list