...

View Full Version : prevent ajax cache?



rnd me
01-07-2009, 10:28 PM
is there a way to prevent caching of ajax calls using request headers?

this is for a library, so i cannot append a timeStamp or make any modifications to the server, or do a post. those are all the suggestions i could find...

i've found a way to encourage caching using If-Modified-Since, but no way to prevent it.

any ideas?

oesxyl
01-08-2009, 12:36 AM
is there a way to prevent caching of ajax calls using request headers?

this is for a library, so i cannot append a timeStamp or make any modifications to the server, or do a post. those are all the suggestions i could find...

i've found a way to encourage caching using If-Modified-Since, but no way to prevent it.

any ideas?
pragma no-cache ?, :)


see section 14.9 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)
best regards

rnd me
01-08-2009, 05:18 PM
thanks for the link.

turns out i was using if-modified wrong, and firebug was lying about the cache.

this was been a real PITA to figure out, and i am surprised it's not better known.


this is how to not get a cache in an ajax call for anyone wondering:




function IO(U, V) {
var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
X.open('GET', U, false);
X.setRequestHeader('If-Modified-Since', 'Sat, 29 Oct 1994 19:43:31 GMT');
X.send(V ? V : '');
return X.status;
}



i can't trust firebug for some reason, but i can time a sync transfer:

with the red line commented, you can pull a page in ~20ms.
trace: [21, 20, 20, 21, 21, 21, 21, 20, 21, 21]


with the red line as is, the performance drops significantly as the data re-transfers.
trace:[109, 63, 64, 64, 61, 61, 59, 61, 61, 61]
(the first one here is erroneous because the connection had timed out)

i also noticed that my router shows a lot more bits coming through when run as is, as compared to being run with the red line commented...


Thus, I am fairly certain this works, but if anyone can make it not work, please share!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum