3

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?

Jeroen
  • 839
  • 13
  • 20

1 Answers1

2

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.

Toon Van Dooren
  • 613
  • 1
  • 12
  • 27
  • Indeed, my question is not 100% clear. The books are created by different people owning different browsers. Your approach may be the only feasible one. The disadvantage of it is (if I am correct) that as soon as a new book is added to the manifest file, the cache of the other books is marked 'out-of-date' and updated by the browers automatically. – Jeroen Feb 15 '12 at 10:04
  • I add new content to my manifest file all the time (automaticly) and everything is still displayed like it should be tough... Just give it a try :) – Toon Van Dooren Feb 20 '12 at 09:09
  • @Jeroen i seemed to have made a mistake, an include of the manifest is only necessary on ur indexpage (just passed trough and noticed :p) – Toon Van Dooren Mar 05 '12 at 21:56