2
votes

I have been trying to figure out HTML5's new AppCache, but I feel extremely limited here.

Let's assume that I have a website with four pages:

index.html
about.html
portfolio.html
contact.html

I have the above resources outlined in the manifiest, along with all of the website's resources. The manifest looks like the below:

CACHE MANIFEST
# 2013-05-23 2:33 PM

# Master Manifest
index.html
about.html
portfolio.html
contact.html
styles/reset.css
styles/styles.css

NETWORK:
*

I have added the appcache file type to the server configuration and have used the correct HTML tag attribute on each page listed above. Just for the record, the element looks like so:

<html lang="en" manifest="example.appcache">

I have tested this setup out on my mobile device, and everything works perfectly fine... Unless I don't load every page. It seems that I have to go to each page and cache it via my mobile browser, after which I may turn off DATA and go offline for my device to be able to browse the APPCACHE'd website.

But, here's my question - How do I setup AppCache to allow me to go to index.html, cache that page, and cache the rest of the resources in the manifest? Without having to visit and manually cache each resource?

If you cannot, then I would have to ask; doesn't that sort of defeat the idea behind AppCache and Offline Accessibility?

Thank you so much for the help all! :)

4

4 Answers

3
votes

You shouldn't need to visit every page. I know you mentioned you've set the MIME type in Apache, but are you 100% certain it's working correctly?

You can check it by opening your manifest in a browser and checking the Response Headers in Chrome Web Inspectors's Network tab:

cache-manifest MIME type

Content-Type should be text/cache-manifest

It's a bit hard to debug without having access to your site, but here's some instructions for how to interpret what happens in Chrome's Web Inspector with AppCache to help you debug the problem yourself:

The Resources tab will show you the contents and status of the Application Cache. It looks like this whilst it's downloading files:

enter image description here

The console will also log events when it's downloading:

Application Cache Progress event (0 of 48) http://cachedfile.url

Once it's done downloading it'll look like this and show you the list of cached files:

enter image description here

When you go back it'll log three events (assuming there aren't any changes):

Document was loaded from Application Cache with manifest http://manifest.url

Application Cache Checking event

Application Cache NoUpdate event

And then when you're offline it looks like this:

enter image description here

Hopefully between the console and the appcache table you'll be able to figure out what's happening.

2
votes

The manifest file is correct and you do not need to visit each page to get in cache in your mobile. You could try if this is a problem with your mobile or browser and if you have defined in your server text/cache-manifest MIME type.

2
votes

The appcache will only store the cache the first time it's downloaded. It's just a list of files that says, when it's downloaded the first time, cache it.

What you could do is after load in the background do an ajax call to load each of the intended resources but it's not particularly pretty.

So looks to me like it's acting how it should be.

CACHE:

This is the default section for entries. Files listed under this header (or immediately after the CACHE MANIFEST) will be explicitly cached after they're downloaded for the first time. http://www.html5rocks.com/en/tutorials/appcache/beginner/

Ahmed

1
votes

I get the following when visiting your site:

Creating Application Cache with manifest http://www.iamaaron.com/appcache/example.appcache

Application Cache Checking event

Application Cache Downloading event

Application Cache Progress event (0 of 6) http://www.iamaaron.com/appcache/styles/reset.css

Application Cache Progress event (1 of 6) http://www.iamaaron.com/appcache/index.html

Application Cache Progress event (2 of 6) http://www.iamaaron.com/appcache/contact.html

Application Cache Progress event (3 of 6) http://www.iamaaron.com/appcache/attendees.html

Application Cache Progress event (4 of 6) http://www.iamaaron.com/appcache/events.html

Application Cache Progress event (5 of 6) http://www.iamaaron.com/appcache/styles/styles.css

Application Cache Error event: Resource fetch failed (404) http://www.iamaaron.com/appcache/styles/styles.css

So, it looks like it's working correctly despite the Content-Type being empty, except for the CSS file which seems to be missing (the URL is wrong, it should be main.css by the looks of things).

BUT my developer tools don't show the app cache being filled and it doesn't work when it's offline.

Try and fix your 404 error with the CSS and make sure your apache it configured correctly to return the correct Content-Type, I reckon that's what's causing issues.