Search code examples
htmljquerycachinghtml5-appcache

Ajax requests and offline cache


I am developping a HTML5 application. I cache all the files thanks to the .manifest solution, so the app can be used when you don't have access to Internet.

I want to synchronise some data to the server whenever it is possible. Since the variable navigator.online seems to not be reliable enough, I do an AJAX request (using jQuery.get()) to detect if I get something in response, meaning the user is online.

The problem is that, as soon as the whole application is cached, every AJAX request towards a file on Internet fails with no reason. I tried on Chrome, Firefox, and Safari (on iPad) with the same result.

I use jQuery.get() to get the content of some files that are part of the application (and cached at the same time), these requests work flawlessly.

I first tought of a Same-origin problem. So I tried to do a request to https://graph.facebook.com, just to see if I get anything in return. In the Chrome console, the request status is "Pending", with 0bytes received.

When I deactivate the manifest and empty the cache, there is no problem at all.

Do you have any idea or hint on why this is happenning ?

Thank you :)

PS : English isn't my mother tongue, so please excuse (and feel free to correct) any mistakes I might have made. :)


Solution

  • Check that you have the network section. The network section of a cache manifest file specifies resources for which a web application requires online access. * is a wildcard which matches all.

    CACHE MANIFEST
    # 2013-11-21:v1
    
    CACHE:
    /Content/Site.css
    /Scripts/jquery-1.8.2.js
    
    NETWORK:
    *
    
    FALLBACK: 
    / /Home/Offline