January 2012
Intermediate to advanced
178 pages
4h 31m
English
Now that you’re comfortable with how the offline app cache works, let’s apply it to the Kilo example we’ve been working on. Kilo consists of quite a few files and manually listing them all in a manifest file would be a pain. Plus, a single typo would invalidate the entire manifest file and prevent the application from working offline.
To address this issue, we’re going to write a little PHP file that reads the contents of the application directory (and subdirectories) and creates the file list for us. Create a new file in your Kilo directory named manifest.php and add the following code:
<?php
header('Content-Type: text/cache-manifest');
echo "CACHE MANIFEST\n";
$dir = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($dir) as $file) {
if ($file->IsFile() &&
$file->getFilename() != "manifest.php" &&
substr($file->getFilename(), 0, 1) != "." &&
!strpos($file, DIRECTORY_SEPARATOR . '.')) { $file_name = $file->getPathName(); if (DIRECTORY_SEPARATOR ...Read now
Unlock full access