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 :)

Richard
  • 31,629
  • 29
  • 108
  • 145
  • I don't think the answer is correct. Please see [this other question on SO][1] [1]: http://stackoverflow.com/questions/10795268/can-i-use-html5-cache-manifest-to-store-third-party-js – user1632306 Apr 17 '13 at 08: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. – Jan Schejbal May 10 '13 at 04:40
  • Please recheck the valid answer – DavidTaubmann May 29 '17 at 15:14

3 Answers3

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.

Jan Schejbal
  • 4,000
  • 19
  • 40
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

Joseph
  • 3,127
  • 2
  • 21
  • 11
  • [W3 specs](https://www.w3.org/TR/2011/WD-html5-20110525/offline.html#writing-cache-manifests): If the manifest is https, all URLs must have the same origin as the manifest – mu3 Feb 04 '17 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.

Divya Manian
  • 1,927
  • 11
  • 16
  • 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. – Jan Schejbal May 10 '13 at 04: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. – Divya Manian Mar 02 '15 at 18:38