Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
837 views
in Technique[技术] by (71.8m points)

web applications - Using Wildcard in FALLBACK section of Cache manifest file HTML5

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]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
";

    $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 . "
";
            $hashes .= md5_file($file);
        }
    }

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

?>

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...