Reputation: 1779
I need to get a large amount of data back from a server via ajax. It will take a bit of time to get to the browser. The second time the user goes back to same web page I don't want them to have to download the data via ajax again. Is there anyway Javascript can write the json data to the browsers cache or filesystem reliably?
Cheers
Rich
Upvotes: 2
Views: 784
Reputation: 1154
You can automatically store the AJAX response into localStorage and use either the network reply or the cached version, as explained here: http://myok12.wordpress.com/2011/08/19/building-an-almighty-data-retrieval-system-for-all-html5-webapps/
Upvotes: 0
Reputation: 85458
That's when you can take advantage of having a RESTful service.
If your requests are made via GET
and are idempotent (eg: same queried URL will always yield the same response), the browser will cache the response.
See: http://ajaxpatterns.org/RESTful_Service
Upvotes: 3
Reputation:
I think if the response has the proper headers, the browser will cache it like any other page. I found this tutorial very informative.
http://www.mnot.net/cache_docs/
Upvotes: 1
Reputation: 1252
As Tim says, localStorage is a good option, however not all browsers support it. As a fallback, you could store the JSON text in the session.
Upvotes: 2