如何在 HTML5 应用程序缓存中缓存多个 HTML 页面,其中包含特定于页面的图像和共享资源?

发布于 2025-01-03 20:24:10 字数 752 浏览 5 评论 0原文

在我的 HTML5 应用程序中,我有几个代表书籍的 HTML 文件。每本“书”都包含该书特定的图像。每个书籍文件还包含对所有书籍共享的 CSS 和 JavaScript 文件的引用。

我想将书籍缓存在 HTML5 应用程序缓存中,以便在没有互联网连接的情况下也可以查看它们。我想我必须为每个 HTML 图书文件创建一个清单文件,其中包含对共享资源和书中图像的引用。 HTML 文件中的标签将如下所示:

<html manifest="Book1.appcache">

或:

<html manifest="Book2.appcache">

和 Book1.appcache 类似:

CACHE MANIFEST
Js/Book.js # Shared
Css/Book.css # Shared
Images/Book1-cover.png # Book-specific

和 Book2.appcache 类似:

CACHE MANIFEST
Js/Book.js # Shared
Css/Book.css # Shared
Images/Book2-cover.png # Book-specific 

我不确定这种设计,这样看来每本书都是它自己的“应用程序”,这不是案件。另外,共享的 CSS 和 JS 文件不是被多次缓存,每本书一次吗?有人可以推荐一个好的解决方案吗?

In my HTML5 application I have several HTML files that represent books. Each 'book' contains images that are specific for that book. Each book file also has references to CSS and JavaScript files that are shared by all books.

I want to cache the books in the HTML5 application cache so that they can be viewed without internet connection. I guess I have to create a manifest file for each HTML book file, containing references to the shared resources and the images in the book. The tags in the HTML files would then look like:

<html manifest="Book1.appcache">

or:

<html manifest="Book2.appcache">

and Book1.appcache like:

CACHE MANIFEST
Js/Book.js # Shared
Css/Book.css # Shared
Images/Book1-cover.png # Book-specific

and Book2.appcache like:

CACHE MANIFEST
Js/Book.js # Shared
Css/Book.css # Shared
Images/Book2-cover.png # Book-specific 

I am not certain about this design, this way it seems each book is its own 'application', which is not the case. Also, aren't the shared CSS and JS files cached multiple times, once for each book? Can anyone recommend a good solution?

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

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

发布评论

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

评论(1

国粹 2025-01-10 20:24:10

你的问题不是 100% 清楚,但这是我的解释。
您可以为每本书存储 2 个单独的文件,但这样存储会导致您在缓存中两次写入 book.js 和 book.css,因此您需要做的是:

Book1.html:

<html manifest="Book.appcache">
<img src="book1-cover.png">

Book2.html:

<html manifest="Book.appcache">
<img src="book2-cover.png">

Book.appcache :

CACHE MANIFEST
Js/Book.js
Css/Book.css
Book1.html
Book2.html
Images/Book1-cover.png
Images/Book2-cover.png

所以你只需制作 2 个单独的 html 文件并缓存它们。

Your question isn't 100% clear but here is how i interpreted it.
You could store 2 seperate files for each book but storing it like that would cause you to write the book.js and book.css twise in your cache so what you need to do is:

Book1.html:

<html manifest="Book.appcache">
<img src="book1-cover.png">

Book2.html:

<html manifest="Book.appcache">
<img src="book2-cover.png">

Book.appcache:

CACHE MANIFEST
Js/Book.js
Css/Book.css
Book1.html
Book2.html
Images/Book1-cover.png
Images/Book2-cover.png

So you just make 2 seperate html files and cache em.

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