[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
>e.g.:
>http://foo.com/bar.html -> http://foo.com/bar.html?12345
>
>http://foo.com/bar.html?foobar=baz -> 
>http://foo.com/bar.html?foobar=baz&12345
>
>
>HTH
>
>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 = 
>>Components.interfaces.nsICachingChannel.LOAD_BYPASS_CACHE;
>>
>>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.
>>
>>Thanks,
>>Andrey
>>_______________________________________________
>>Project_owners mailing list
>>Project_owners at mozdev.org
>>http://mozdev.org/mailman/listinfo/project_owners
>>
>_______________________________________________
>Project_owners mailing list
>Project_owners at mozdev.org
>http://mozdev.org/mailman/listinfo/project_owners




More information about the Project_owners mailing list