[Project_owners] XMLHttpRequest - how can one bypass cache?

Konstantin Svist fry.kun at gmail.com
Thu Aug 3 13:43:59 EDT 2006

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 = 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

More information about the Project_owners mailing list