AppCache with PhoneGap and Jquery mobile

2019-09-08 08:16发布

I recently set my appname.appcache contents to this:CACHE MANIFEST

# 2010-02-10 v1

CACHE:
index.html
test1.html
test2.html
# many more project root html files

#stylesheets
css/main.css
css/normalize.css
css/themes2/jquery.mobile-1.0.min.css

#gameMessages
some-folder/name.html
#many more like this

#js
js/vendor/jquery.mobile-1.0.1.min.js
# a few more files

Now when I navigate to index.html I get an error in google-chrome:

Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. file:///home/username/Desktop/project-name/test1.html

XMLHttpRequest cannot load file:///home/user-name/Desktop/project-name/test1.html. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

In phonegap's config.xml file:

<access origin="*"/> 

So does this solve the problem when run on real mobile devices. And why am I getting this error just on Chrome. On Firefox it runs fine, by asking for a permission to store files.

And does appCache improve performance for application built with phonegap?. Does Caching resources already available on hardware make things faster? I know that content on cache than those on HD are processed really quick. Hence the appCache facility is used in this case.

2条回答
成全新的幸福
2楼-- · 2019-09-08 08:39

Not really an answer but thanks for pointing me in the right direction in solving my own problem. (posted here in case it ever helps someone with a similar issue - I tried adding just a comment but the text is too long)

I'd been using a cache manifest for the web version of an app I'm building but hadn't considered it for the PhoneGap build. When you ask "does appCache improve performance for application built with phonegap?" for me at least, the resounding answer is a big yes.

I'm using magnificPopup loading ajax type pop-ups, all worked fine (even when the phone/device is offline) except for when the popup content includes a RoyalSlider gallery - these successfully load the ajax content (I can tell thanks to magnificPopup's very useful ajax callbacks) but they don't go on to add this to the DOM. I still have no idea exactly why that is, I'm guessing the problem is somewhere in RoyalSlider's code, perhaps looking for a resource it considers to be online? But anyways, implementing a cache manifest has completely solved the problem for me. Thanks.

查看更多
三岁会撩人
3楼-- · 2019-09-08 08:49

I had also get the same error, but in my case it was due to the fact that i was running my file on http and caching resources which were on https therefore not on the same origin. If you have that kind of issue you can look into it.

查看更多
登录 后发表回答