14

I'm building an offline web application and want to use cache-manifest. Currently my cache-manifest looks like this:

CACHE MANIFEST
# Change the version number below each time we update a resource.
# Rev 1
index.html
photo.html
js/photo.js
css/photo.css
http://code.jquery.com/jquery-1.6.1.min.js
http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js
http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css
http://maps.google.com/maps/api/js?sensor=false&region=GB

Is there any reason not to include external, CDN-hosted jQuery, jQuery Mobile and Google Maps files in the cache-manifest?

I can't think of one, but I thought I would ask those wiser than myself :)

3
  • I don't think the answer is correct. Please see [this other question on SO][1] [1]: stackoverflow.com/questions/10795268/… Apr 17, 2013 at 8:53
  • 1
    Please recheck answers; I suspect the accepted answer is incorrect and it caused a lot of confusion. I have provided a different answer with sources. May 10, 2013 at 4:40
  • Please recheck the valid answer May 29, 2017 at 15:14

3 Answers 3

19

Yes. Actually, you must include external images in your manifest, or some browsers will not load them at all even if a network connection is available! (Unless you provide a NETWORK section, which may cause the images to be fetched every time, bypassing the regular browser cache.)

The images will be cached (at least by Firefox, didn't test Chrome).

The spec explicitly says:

Offline application cache manifests can use absolute paths or even absolute URLs

http://manifest-validator.com/ also reports a manifest with external URLs as OK.

I am not 100% sure this also applies to scripts, but a quick test with Firefox looked like the script is cached as expected.

2

MobileSafari has a rule that under SSL, all paths in the applicationCache must conform to same-origin policy. The applicationCache will cache successfully with foreign-origin paths, but you will not see those resources listed in the Web Inspector->Storage->ApplicationCache table, and they will not be available when offline.

This behavior isn't described in Apple's documentation but is still apparent in iOS 10.2: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html

1
  • W3 specs: If the manifest is https, all URLs must have the same origin as the manifest
    – mu3
    Feb 4, 2017 at 20:10
-7

You cant. Cache Manifest will only work for files from same domain. You would need to proxy from your domain if you want to white-list for cross-domain resources.

2
  • 6
    This answer is INCORRECT at least for images, but probably also for scripts (please see my answer for sources). Please check again and either provide a source or delete/correct the answer, since this comes up in Google searches and is very confusing. May 10, 2013 at 4:39
  • 1
    Lol folks this was answered in 2011 (almost 3 years ago!) geesus. Original poster can mark it as incorrect and update with the right answer. Mar 2, 2015 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.