HTML5 - 如何离线使用远程但缓存在清单中的资源?

发布于 2024-12-16 11:46:32 字数 623 浏览 5 评论 0原文

HTML5 清单允许指定资源的绝对链接,例如:

CACHE MANIFEST

http:// /www.xerox.com/downloads/usa/en/x/xes_3000Series_Brochure.pdf

Chrome/Safari 控制台日志显示该文件已按照指定正确缓存在清单文件中。但是如何在 iOS/Android 上离线访问该文件呢?我将链接完全按照清单中的绝对 URL 放在页面上,当我在线时,它正在打开,在普通模式下浏览器打开应用程序,但指向 pdf 的链接不起作用,它说需要互联网连接,可能是合乎逻辑的,因为链接是绝对的,但我希望它会首先检查清单。

也许有某种方法可以使用 javascript 访问清单缓存项目,并提供文件链接作为缓存中的某个实例,换句话说,使其像具有亲戚 url 的项目一样工作,这不会导致任何问题。或者其他一些解决方法。请指点我,我错过了什么吗?

更新:我正在使用 jQuery Mobile 框架,也许这也会有帮助,也许有人已经处理过这个问题,但我在文档和官方论坛中没有找到任何关于这个问题的有用信息。

HTML5 manifest allows to specify absolute links to resources, example:

CACHE MANIFEST

http://www.xerox.com/downloads/usa/en/x/xes_3000Series_Brochure.pdf

Chrome/Safari console log shows that file cached correctly as it's specified in manifest file. But how to get access to this file offline on iOS/Android? I putted link on page exactly as in manifest, absolute URL, when i'm online it's opening, in airplain mode browser opens application, but link to pdf not working, it says that internet connection required, probably it's logical, as link is absolute, but i was hoping that it will check in manifest first.

Maybe there is some way to get access to manifest cached items using javascript and provide link to file as some instance in cache, in another words to make it work like items with relatives urls, which are causes no problems. Or some other workaround. Please point me, am i miss something?

UPDATE: I'm working with jQuery Mobile framework, maybe this would help too, maybe someone has dealed with that, but i didn't find anything helpfull about this question in documentation and official forum.

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

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

发布评论

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

评论(2

写给空气的情书 2024-12-23 11:46:32

您无法直接访问此资源。 AppCached 文件只能从 标记中包含给定清单的页面访问。

当您访问 PDF 时,您会离开原始页面,并且浏览器(正确地)会忽略清单。

只是一个想法,您是否尝试过将 PDF 嵌入 中?

You cannot access this resource directly. AppCached files are only accessible from pages featuring the given manifest in their <html> tag.

When you access the PDF, you leave the original page and the browser (correctly) ignores the manifest.

Just an idea, have you tried embedding the PDF in an <iframe>?

深府石板幽径 2024-12-23 11:46:32

最好能够在浏览器中打开 pdf,并根据需要为用户选择不同的阅读器。经过更多测试后,我得出的结论是您所说的是错误的,尽管第一个想法是您是对的。即使您在清单中设置相对网址,当您在链接中将其用作相对网址时,考虑到该应用程序已缓存,生成的网址无论如何都会成为浏览器的绝对网址,但我可以直接访问该文件。相对网址没有问题的原因是它是小尺寸的图像,而现在我正在处理大尺寸的 pdf。我的结论是,您使用的相对或绝对网址并不重要,如果这些文件被缓存,您就可以访问它们。问题是 iPad 和 iPhone 的缓存限制为 5Mb,如果清单文件大于设备请求您增加应用程序可用大小的大小,但它会完全停止缓存过程。所以我想我需要研究一些部分缓存 5Mb 和动态清单的解决方法。所以现在它变成了一个不同的问题。哇!我以为这会更容易,该死的pdf))

It's better to have possibility to open pdf in browser and choose different reader for users if they wants. After more testings i come to conclusion that what you said is wrong, althought the first thought was that you are right. Even if you set relative urls in manifest, than when you use it in links as relative too the resulting url become an absolute for browser anyway, considering that app is cached, but i can get direct access to that files. The reason why didn't have problems with relative urls is that it was small-sized images and now i'm dealing with big-sized pdfs. My conclusion is that it's doesn't matter relative or absolute url you are using, you can get access to that files if they are cached. The problem is that iPad and iPhone have cache limit 5Mb, if manifest file is larger than that device requested to you to increase available size fr your app, but it stops caching process completely. So i suppose i need to look on some workaround of partial caching by 5Mb at one part and dynamic manifest. So now it's become a different question. Wow! I thought it would be easier, damn pdfs))

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