[Project_owners] XMLHttpRequest - how can one bypass cache?

Roman Mironenko roman_mir at hotmail.com
Fri Aug 4 00:50:26 EDT 2006

Yeah, I had to deal with the same problem in RussKey extension (it 
translates text on page to and from Russian by going to one of predefined 
translator sites) and in the StockTicker extension, so I also used a time 
variable in the URL.  Just waiting for Amazon to patent this technique any 
time now...

>had the same problem a long time ago.
>the way to solve it is to append current time to the request url.
>random strig doesn't help since it might repeat.
>here's my hacky way of doing it (noCache is a parameter to the 
>xmlhttprequest handling function, defaults to true):
>// use the time hack if caller doesn't want cached request
>if (noCache) {
>   url += (url.match(/\?/) == null ? '?' : '&') + (new Date()).getTime();
>This should append the unix time to the request as a parameter, taking care 
>to insert a ? or & when needed
>http://foo.com/bar.html -> http://foo.com/bar.html?12345
>http://foo.com/bar.html?foobar=baz -> 
>Andrey Gromyko wrote:
>>Hi All,
>>In the NewsFox extension I use next lines to download feed(s):
>>     var xmlhttp = new XMLHttpRequest();
>>     xmlhttp.open("get", feed.url);
>>     xmlhttp.setRequestHeader("User-Agent", "Mozilla/5.0 NewsFox/0.3.4");
>>     xmlhttp.overrideMimeType("application/xml");
>>     xmlhttp.onload = function() { checkFeed(index, xmlhttp.responseXML); 
>>     xmlhttp.send(null);
>>Adding the next line before send doesn't help to avoid the use of 
>>Firefox's cache:
>>     xmlhttp.channel.loadFlags = 
>>And that causes problems with some feeds. Does anybody know how can I 
>>bypass the cache? Similarly tp the behaviour of the browser when somebody 
>>pressed Shift+Reload.
>>Project_owners mailing list
>>Project_owners at mozdev.org
>Project_owners mailing list
>Project_owners at mozdev.org

More information about the Project_owners mailing list