Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't the browser just use its cache from prior ajax calls?
    primarykey
    data
    text
    <p>I am trying to rely upon the browser cache to hold JSON data returned from AJAX calls in jQuery.</p> <p>Normal browser activity relies upon the browser cache all the time. Example: jpg and gif images are not refetched on a page reload.</p> <p>But when I try using jQuery getJSON ajax calls, I cannot seem to avoid fetching the data from the server.</p> <p>My returned headers look like this (confirmed with firebug):</p> <pre><code>Transfer-Encoding: chunked Date: Wed, 05 Aug 2009 02:55:39 GMT Content-Type: text/plain; charset=ISO-8859-1 Expires: Wed, 05 Aug 2009 03:55:39 GMT Cache-Control: max-age=3600 </code></pre> <p>Yet an immediate refresh of the page causes identical requests to hit the server.</p> <p>I've seen several postings about avoiding caching behavior, which isn't what I need. I've seen several postings about utilizing caching, but those all seem to rely upon saving data in the DOM. I want something that behaves just like cached images do during a page reload.</p> <p>Cant the browser just fetch it from it's own cache?</p> <p>--x--x--x--x UPDATE --x--x--x--</p> <p>Much to my disappointment, several respectable folks agree that this isn't just possible. Some even argue that it shouldn't be (which still baffles me).</p> <p>Stubburn to a fault, I tried the following:</p> <p>I set the Etag header on all outgoing pages I want to be cached (I pick a few choice URL arguments that represent the data I'm requesting and just use that for the Etag value)</p> <p>At the beginning of the next request, I simply check if the 'If-None-Match' header is in the request. If so, then the browser isn't caching the request like I wanted, so I sent a 304 Not Modified response.</p> <p>Testing shows that Firefox won't cache my request (but I can still avoid the 'fetch the expensive data' part of my cgi), while IE6 will actually cache it (and wont even attempt fetching back from the server).</p> <p>It's not a pretty answer, but it's working for me for now<br> (those pesty full-page refreshes of graph data wont be so slow or expensive now).</p> <p>(What? I'm running IE6! OMG! Oh look a squirrel!)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload