Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get simple html5 manifest cache to work!

Tags:

html

manifest

I'm trying to get a simple html5 webcache to work.

This is my one and only html page, index.html:

<!DOCTYPE HTML>

<html manifest="./main.manifest">
  <body>
    <p>Hi.</p>
  </body>
</html>

This is my only cache file, main.manifest:

CACHE MANIFEST
# 2011-05-02-03

index.html

I'm running on apache shared hosting, I put a .htaccess file in my web directory where these other two files are, because I thought maybe I have to define the mime type:

AddType text/cache-manifest .manifest

So in the end I just have these three files in that directory:

index.html
main.manifest
.htaccess

When I visit the page on chrome from my mac, safari from my iphone, or chrome from my android 2.3 device, nothing happens, the page just loads as usual. If I turn airplane mode on (killing all connections) the page can't be loaded (so I guess caching failed).

What am I missing here?

Thanks

------------ Update ------------------

I think the mime type was not being recognized correctly. I updated .htaccess to:

AddType text/cache-manifest manifest

Now if I run in google chrome with console on, I see:

Document was loaded from Application Cache with manifest
http://example.com/foo/main.manifest
Application Cache Checking event
Application Cache NoUpdate event

Firefox prompts me when I load the page about the website wanting to let me store it to disk, so that's good. Looks like it's also working on android 2.3.4. The browser still says "This page cannot be loaded because you are not connected to the internet", but then it loads anyway.

Thanks!

like image 369
user291701 Avatar asked May 02 '11 22:05

user291701


1 Answers

First, you were right the first time on your mime type declaration. It should be like this:

AddType text/cache-manifest .manifest

Next, read this paragraph from Dive Into HTML5:

Q: Do I need to list my HTML pages in my cache manifest?

A: Yes and no. If your entire web application is contained in a single page, just make sure that page points to the cache manifest using the manifest attribute. When you navigate to an HTML page with a manifest attribute, the page itself is assumed to be part of the web application, so you don’t need to list it in the manifest file itself. However, if your web application spans multiple pages, you should list all of the HTML pages in the manifest file, otherwise the browser would not know that there are other HTML pages that need to be downloaded and cached.

So, in this case, you don't need a cache manifest. The browser will automatically cache your page (as long as it's the only resource, such as a CSS file or Javascript file, for example).

For more information, visit the link above.

like image 149
alexanderpine Avatar answered Sep 23 '22 04:09

alexanderpine