Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i allow json requests when using HTML5's appcache feature?

When i added appcache to my webapp running jquery mobile, all the ajax-calls requesting json-files from my server stoppet working. My manifest-file looks like this:

CACHE MANIFEST

CACHE:

index.html
scripts/jquery-1.7.1.min.js scripts/jquery.flot.min.js
scripts/jquery.flot.threshold.min.js
scripts/jquery.mobile-1.0.1.min.js
styles/jquery.mobile-1.0.1.min.css
styles/touchStyles.css
styles/styles.css

NETWORK: 

index.appcache
dataFetchAndDraw.js
initJson

Where initJson is one of the calls that won't work. i've tried to enter the full address(aaa:bbb:ccc:ddd:6565/initJson) also without success.

In my .htaccess file i only have this one line:

AddType text/cache-manifest .manifest
like image 610
user1274438 Avatar asked Mar 16 '12 16:03

user1274438


2 Answers

I just ran into this issue and had to add a wildcard to the NETWORK section of the manifest file to allow the browser to go to the network for any non-cached resources.

NETWORK:
*
http://*

You apparently need both wildcard entries above to support all the browsers.

I also found appcachefacts.info a useful resource to understand this and other specifics about appcache. I recommend reading this all the way through before continuing up the appcache learning curve:

The NETWORK section lists all URLs that may be loaded over the Internet. If your application includes any API calls, make sure to enumerate them here. Note that this is a list of URL prefixes, so if all of your network calls begin with http://example.com/api/, that's all you need to include.

If you want to allow arbitrary URLs to be accessed (scripts, stylesheets, API calls, anything), include*, http://* and https://* in this section. (Chrome and Safari respect the*; Firefox needs the http://* and https://*.)

like image 191
Chad Pavliska Avatar answered Sep 18 '22 08:09

Chad Pavliska


I had a similar problem with an application I was working on, the problem I had was the cache flag in the ajax call was defaulting to true.

I found that when I added

cache : false

to my ajax GET request the request hits the server. (http://api.jquery.com/jQuery.ajax/)

like image 35
Adam Avatar answered Sep 22 '22 08:09

Adam