sean
sean

Reputation: 11644

weird html5 manifest reloading

I'm having a strange problem with the HTML5 manifest file under Chrome 5.0.375.99 but everything seems to be working fine under Safari.

When loading a page for the first time with the manifest file specified for the first time, I can observe using Fiddler that all the files in the manifest being loaded and then halfway through it seems to get the manifest file again. At this point, the error event is triggered and the status of the applicationCache is UNCACHED.

I've tried the following

  1. reboot pc
  2. restart browser
  3. check that the amount of files being cached does not exceed 5mb
  4. check that the files in the manifest file is valid by doing a HEAD
  5. Tried using a different manifest filename

Upvotes: 3

Views: 3079

Answers (2)

mattdlockyer
mattdlockyer

Reputation: 7314

I finally solved this on my end.

I'm lazy and I want my server to dynamically generate my cache-manifest for me.

This module export is the answer to the request for the cache-manifest on my server.

Thanks for the tip about the two requests, so here's how I did it with node:

//OFFLINE CACHE
var cacheManifest = undefined;

exports.cache = function(req, res){
    if (!cacheManifest) {
        var fsutils = require('modules/utils/fsutils');
        //get the files and generate the output for cache.manifest
        fsutils.getFiles('/public', function(files) {
            var out = 'CACHE MANIFEST\n\ ';
            var len = files.length;
            for (var i = 0; i < len; ++i) {
                out += files[i] + '\n\ ';
            }
            //setup for second request
            cacheManifest = out;
            //send output
            res.header('Content-Type', 'text/cache-manifest');
            res.end(out);
        });
    } else {
        console.log('cache is cahced');
        res.header('Content-Type', 'text/cache-manifest');
        res.end(cacheManifest);
    }
};

The trick here is to not rebuild your cache-manifest with every request. Basically the user only gets the manifest the first time they land on your app, if it's changed, or you can force it to expire through client or server side code.

The first visit will always generate the latest manifest then you can do whatever you want after that.

I had the error because I was (moronically) generating the cache-manifest doc with each request and since chrome does the back up second request it wasn't matching and failing.

Danm...

Upvotes: 1

sean
sean

Reputation: 11644

I've just installed Chrome dev channel and the problem still occurs but now the error logging is better and I get "Application Cache Error event: Manifest changed during update, scheduling retry"

It seems Chrome checks the manifest file if it has changed just before downloading the last entry in the manifest file. The error happens because I used the current timestamp value in the dynamically generated manifest file.

Used timestamp of the time my assembly was built and the problem went away. :)

Upvotes: 9

Related Questions