Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Ajax with Offline Cache

I'm working on an offline-capable application and I'd like to do an ajax call to $.get() a file on the domain that I will be caching.

Will the call still work if I'm offline? I would presume no, but I wondered if I included the static page in the offline cache if it would somehow still work.

like image 399
doremi Avatar asked Apr 27 '11 22:04

doremi


People also ask

Can you use Ajax offline?

Since the Ajax applications communicate with the Hub via the server, you cannot operate the Hub via applications in the case of Internet connection failure.

Can Ajax requests be cached?

There is however a better solution – caching AJAX requests. Although we can use a standard caching solution provided by HTTP (yes, Ajax is cached by HTTP), there is a catch: It works for GET requests only (not POST). Furthermore, you cannot control cache expiration on the application side.

Which functionality did not use Ajax?

10. Which of the following technology is not used by Ajax? Flash is not used by Ajax.

How Ajax get data from server?

The $.get() method requests data from the server with an HTTP GET request. Syntax: $.get(URL,callback); The required URL parameter specifies the URL you wish to request.


2 Answers

Short answer: Yes.

If you have the file in the application cache, then all HTTP GET requests (including Ajax) will go through the cache. You can think of an Ajax GET request as an ordinary browser page load, but the results are delivered to your code rather than directly to the user.

like image 181
mgiuca Avatar answered Sep 29 '22 21:09

mgiuca


You can cache the responses into local storage and use the saved one when offline. See more on how to make this automatic here: http://myok12.wordpress.com/2011/08/19/building-an-almighty-data-retrieval-system-for-all-html5-webapps/

like image 42
Ohad Kravchick Avatar answered Sep 29 '22 20:09

Ohad Kravchick