XMLHttpRequest in FireFox and browser cache

Discussion in 'Javascript' started by Sergey Surkov, Jun 4, 2005.

  1. 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.
    Sergey Surkov
    Sergey Surkov, Jun 4, 2005
    1. Advertisements

  2. Sergey Surkov

    VK Guest

    yourRequest.setRequestHeader("Pragma", "");

    (Takes out of the game Opera & Co though, because their XmlHttpRequest
    is broken on headers mechanics).
    VK, Jun 4, 2005
    1. Advertisements

  3. Sergey Surkov wrote:

    You can set HTTP request headers if you need to
    var httpRequest = new XMLHttpRequest();
    httpRequest.open('GET', 'file.xml', true);
    'desired cache value here')
    Martin Honnen, Jun 4, 2005
  4. 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 Surkov, Jun 4, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.