[英]Is it possible to generate a html5 cache manifest dynamically?
很確定,但是讓我告訴你:讓HTML5離線內容與JavaScript applicationCache.update()等完美配合。 人。 如果你是新手,有點麻煩。 最終一切都有效......記錄在案! 但是CAVEAT LECTOR ......
無論如何,這是一個(希望)自我解釋的PHP專用示例,您需要一個.htaccess
文件。 這將告訴您的服務器將cache.manifest
解釋為PHP代碼(因為沒有.php
擴展名,所以需要)。
您的.htaccss
文件,以防您使用FCGI Wrapper:
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;
祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.