CDN 上的应用程序缓存清单?

发布于 2024-12-05 13:34:55 字数 759 浏览 1 评论 0原文

我正在阅读有关 HTML5 应用程序缓存清单的详细信息(尤其是来自这篇优秀文章)。我很好奇这个想法是否可行:

我们将所有静态资源(脚本、CSS、字体、图像)托管在子域内的 CDN 上(例如 cdn.example.com,应用程序位于 www.example.com)。是否也可以在 CDN 上托管应用程序缓存清单?例如,

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

如果是,清单列表可以来自 CDN 根吗?例如,在清单中:

CACHE MANIFEST
/foo.js

是否有人有这方面的经验和/或知道任何警告?


编辑: WHATWG 规范的工作草案表示“离线应用程序缓存清单可以使用绝对路径甚至绝对 URL",然后显示带有图像 CDN URL 的示例。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

依 靠 2024-12-12 13:34:55

我用我的清单进行了测试(在真实的例子中)

CACHE MANIFEST
# 2010-06-20:v1

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

它对我有用...您可以使用验证器 http:// 检查清单manifest-validator.com/

W3C只说文档(具有manifest属性的HTML文件)必须与manifest同源,他们没有告诉资源的URL也必须是同源的......你应该仔细阅读它(此处)。我还在 W3 示例中找到了跨站点 URL(检查此处< /a>),这意味着它可以正常工作...

最后,不要尝试将清单文件放在 CDN 上,只需将其放入您的服务器并将资源链接到 CDN 即可。清单文件必须与其主条目具有相同的来源,其中包括它们的 HTML 文件,并且浏览器检查清单文件以查看其 HTML 页面列表是否已更改,而不是检查您的 HTML 页面以查看它是否指向不同的清单文件。

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.

夜空下最亮的亮点 2024-12-12 13:34:55

缓存内容必须满足同源限制,比较的来源由调用页面(HTML页面)决定。如果您尝试缓存的所有资源都具有不同的主机名,那么根据规范,它们应该被拒绝。因此,即使您可以指定清单位于 cdn 上而不是您的主主机上,缓存也应该会失败。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文