XMLHttpRequest in FireFox and browser cache

S

Sergey Surkov

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
 
V

VK

Try
....
yourRequest.setRequestHeader("Pragma", "");
yourRequest.send(null);
....

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

Martin Honnen

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')
 
S

Sergey Surkov

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top