App cache manifest on CDN?
Asked Answered
S

2

9

I'm reading through details on HTML5's app cache manifest (especially from this excellent article). I'm curious if this idea would work:

We host all of our static resources (scripts, css, fonts, images) on a CDN within a subdomain (e.g. cdn.example.com and app is on www.example.com). Is it possible to host the app cache manifest on the CDN as well? For example,

<!doctype html>
<html manifest="http://cdn.example.com/appcache.manifest">
...
<script src="http://cdn.example.com/foo.js"></script>
...
</html>

If yes, can the manifest listings be from the CDN root? For example, in the manifest:

CACHE MANIFEST
/foo.js

Does anyone have any experience with this and/or know of any caveats?


EDIT: The working draft of the WHATWG spec it says "Offline application cache manifests can use absolute paths or even absolute URLs" and then shows an example with CDN URLs for images.

Samuels answered 20/9, 2011 at 2:9 Comment(0)
P
12

I tested with my manifest (in real example)

CACHE MANIFEST
# 2010-06-20:v1

iscroll.js
http://peach.blender.org/wp-content/uploads/big_big_buck_bunny.jpg

It works to me... You can check you manifest with validator http://manifest-validator.com/.

W3C only says the document (HTML file that have manifest attribute) must be same origin source with the manifest, they don't tell URL of resources must be too... You should read it carefully (at here). I also found the cross-site URL in W3 example (check here), that means it works correctly...

Finally, DON'T TRY TO PUT MANIFEST FILES ON CDN, JUST PUT IT IN YOUR SERVER AND LINK RESOURCE TO CDN. Manifest files have to have the same origin as their master entries, which includes their HTML files, and the browser checks the manifest file to see if its list of HTML pages has changed, rather than checking your HTML page to see if it points to a different manifest file.

Publicspirited answered 15/4, 2012 at 4:11 Comment(8)
“DON'T TRY TO PUT MANIFEST FILES ON CDN” — why not?Honegger
Just my recommendation... Because the CDN will cache those manifest files, and it's hard to clear cache on CDN.Publicspirited
depends how you do it. (E.g. you can append a hash of the manifest file's contents to its filename when it changes, and then update your HTML pages to point to the new filename on the CDN. That process can be automated.) But I see your point.Honegger
Actually, you CANNOT update your HTML page if you use manifest cache.Publicspirited
eh? Do you mean if you use a cache manifest on an HTML page, browsers will never again check your HTML page for changes?Honegger
Yes, that's right. Please read more at here: whatwg.org/specs/web-apps/current-work/multipage/offline.html , HTML page is named "master entries". By the way, I found in that page, it says: All the master entries have the same origin as the manifest.Publicspirited
ah, so I guess you couldn’t put your manifest on a CDN anyway, as it has to have the same origin as your master entries (i.e. your HTML pages). And it sounds like the cache manifest is the thing that’ll get checked (according to its HTTP caching rules) for changes, rather than your main HTML file. So you wouldn’t want it to have a far-future expiry date like a typical CDN resource.Honegger
I’ve had a go at editing your answer to include this information. Thanks for explaining it, I understand the cache manifest stuff much better now.Honegger
P
0

The cached contents must satisfy the same origin restriction and the origin for comparison is determined by the calling page (the HTML page). If all of the resources you are trying to cache have a different host name then according to the spec they should be rejected. So even if you could specify the manifest to be on the cdn and not your main host, the caching should fail.

Pr answered 20/9, 2011 at 12:57 Comment(1)
Taking me a while to get back to checking this out but I'm not sure that this answer is correct. Looking at the working draft of the WHATWG spec it says "Offline application cache manifests can use absolute paths or even absolute URLs" and then shows an example with CDN URLs for images. (whatwg.org/specs/web-apps/current-work/multipage/offline.html) I believe the same origin restrictions is only for fallback entries.Samuels

© 2022 - 2024 — McMap. All rights reserved.