非常肯定,但让我告诉你:让 HTML5 离线内容与 JavaScript applicationCache.update() 等很好地协同工作。人。如果您是新手,那会有些混乱。最后,一切都按照……记录在案!但是警告讲师...
无论如何,这是一个(希望如此)自我解释的仅限 PHP 的示例,您需要一个 .htaccess 文件。这将告诉您的服务器将 cache.manifest 解释为 PHP 代码(需要,因为没有 .php 扩展名)。
如果您使用 FCGI Wrapper,您的 .htaccss 文件:
AddType text/cache-manifest .manifest
<FilesMatch "\.(manifest)$">
SetHandler fcgid-script
FcgidWrapper /folder/to/your/php-fcgi-starter .manifest
Options +ExecCGI
</FilesMatch>
您的.htaccess 文件,以防您使用 apache php 模块(大多数情况下,这将是默认情况):
AddType text/cache-manifest .manifest
<FilesMatch "\.(manifest)$">
SetHandler application/x-httpd-php
</FilesMatch>
您的cache.manifest 文件:
<?php
// only cache files in the following folders (avoids other stuff like "app/")
$folders = array('js', 'lib', 'views', 'styles');
$files = array('index.html');
// recursive function
function append_filelist(&$files, $folder) {
if ($dh = opendir($folder)) {
while (($file = readdir($dh)) !== false) {
if ( ! in_array($file, array('.', '..', '.svn')) &&
(substr($file, -4) != ".swp")) {
if (is_dir($folder."/".$file))
append_filelist($files, $folder."/".$file);
else
//$files[] = $folder."/".$file."?hash=".md5_file($folder."/".$file);
$files[] = $folder."/".$file;
} // if
} // while
} // if
}
// init
foreach ($folders as $folder)
if (is_dir($folder))
append_filelist($files, $folder);
// generate output
$body = "CACHE MANIFEST\n\nCACHE:\n";
foreach ($files as $file)
$body .= $file."\n";
$body .= "\nNETWORK:\n*\n";
// render output (the 'Content-length' header avoids the automatic creation of a 'Transfer-Encoding: chunked' header)
header('Content-type: text/cache-manifest');
header('Content-length: '.strlen($body));
echo $body;
祝你好运!