views:

161

answers:

2

How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]

A: 

It's not possible to use wildcards in the cache manifest, at least it doesn't work in any current browser as far as I'm aware. An alternative approach might be to generate your cache manifest dynamically, and let a script generate all those fallback entries.

robertc
yeah, it seems that probably I have to generate [growing] FALLBACK dynamically. Thanks for confirming my fear.
ashishb
@ashishb I've just discovered that the current Firefox 4.0 nightly does support wildcards in the fallback section. Still doesn't work in Chrome or Opera dev versions though.
robertc
A: 

I reference "manifest.php" instead of "cache.manifest", then my php file looks like this:

<?php
    header('Content-Type: text/cache-manifest');
    echo "CACHE MANIFEST\n";

    $hashes = "";

    $dir = new RecursiveDirectoryIterator(".");
    foreach(new RecursiveIteratorIterator($dir) as $file) {
        $info = pathinfo($file);
        if ($file->IsFile() &&
            $file != "./manifest.php" &&
            substr($file->getFilename(), 0, 1) != ".")
        {
            echo $file . "\n";
            $hashes .= md5_file($file);
        }
    }

    echo "# Hash: " . md5($hashes) . "\n";

?>

The file hashes keep it up-to-date so that if any files change the manifest changes as well. Hope that helps :)

dosboy
but how do I generate FALLBACK entries?
ashishb
You would just have to build some logic into that script to list FALLBACK files (based on path, filename, etc.) separately. Loop once, exclude FALLBACK files. Loop again, only include FALLBACK files.
dosboy