By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,197 Members | 1,670 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,197 IT Pros & Developers. It's quick & easy.

XMLHttpRequest in FireFox and browser cache

P: n/a
Hello
Does anybody know how to make FireFox to cache data that comes via
XMLHttpRequest? Here is the issue I deal with:
- On the web server (apache2) I have a static xml file test.xml
- When I download test.xml using XMLHttpRequest, FireFox always gets
complete test.xml from the server, thus not using the browser cache
(apache sends 200 OK back to FireFox).
- If I look into the HTTP request and the HTTP response, I can see
that FireFox seems to always set the following request headers:
Pragma: no-cache
Cache-Control: no-cache
- Apache always sets Last-Modified and ETag headers in a response.

I tried the same JavaScript code with IE, and IE definitely relies on
its cache: I can see in Apache logs responses with 304 Not Modified
code for IE, also HTTP requests from IE have If-Modified-Since and
If-None-Match headers. I didn't find any difference in responses Apache
provides for FireFox and IE.

Any ideas? It would be nice to make caching work in FireFox.
Regards,
Sergey Surkov

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VK
Try
....
yourRequest.setRequestHeader("Pragma", "");
yourRequest.send(null);
....

(Takes out of the game Opera & Co though, because their XmlHttpRequest
is broken on headers mechanics).

Jul 23 '05 #2

P: n/a


Sergey Surkov wrote:

Does anybody know how to make FireFox to cache data that comes via
XMLHttpRequest? Here is the issue I deal with:
- On the web server (apache2) I have a static xml file test.xml
- When I download test.xml using XMLHttpRequest, FireFox always gets
complete test.xml from the server, thus not using the browser cache
(apache sends 200 OK back to FireFox).
- If I look into the HTTP request and the HTTP response, I can see
that FireFox seems to always set the following request headers:
Pragma: no-cache
Cache-Control: no-cache
- Apache always sets Last-Modified and ETag headers in a response.

I tried the same JavaScript code with IE, and IE definitely relies on
its cache: I can see in Apache logs responses with 304 Not Modified
code for IE, also HTTP requests from IE have If-Modified-Since and
If-None-Match headers. I didn't find any difference in responses Apache
provides for FireFox and IE.


You can set HTTP request headers if you need to
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'file.xml', true);
httpRequest.setRequestHeader('Cache-Control',
'desired cache value here')

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

P: n/a
Thanks for the reply. I couldn't make it work, though.
It seems that the meaning of setRequestHeader for these two headers
(Pragma and Cache-Control) is extension of the defaults, not
replacement. For example, if I say setRequestHeader("Cache-Control",
"public"), the actual header becomes Cache-Control: no-cache, public.
Or if I say setRequestHeader("Pragma", "sergey=sergey"), the result is
Pragma: sergey=sergey, no-cache. Other headers may work differently: I
tried modifying Keep-Alive and the resulting header was correct.

I'm also inclined to think that if there is a solution to the
problem, it shouldn't deal with manually setting HTTP request headers.
The reason is for a browser to send a conditional GET, it has to
provide an ETag or a last modified date so that a server could
determine if the cache entry is osbsolete. These values are stored (if
they are stored) inside browser cache and are probably not available to
JavaScript on a web page.

Am I still missing something? Does anybody have a successfull
experinece of Firefox using browser cache for XMLHttpRequest
transactions? Maybe it's a well known bug and there is a workaround?

Sergey

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.