Mat*_*der 3 php html5 dynamic cache-manifest
是否可以动态生成html5缓存清单?我已经尝试过php(遵循本教程以及其他http://grinninggecko.com/dynamic-cache-manifest/)但没有成功.
小智 9
很确定,但是让我告诉你:让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>
Run Code Online (Sandbox Code Playgroud)
你的.htaccess文件,以防你使用apache php模块(大多数情况下,这将是默认情况):
AddType text/cache-manifest .manifest
<FilesMatch "\.(manifest)$">
SetHandler application/x-httpd-php
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
你的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;
Run Code Online (Sandbox Code Playgroud)
祝好运!
| 归档时间: |
|
| 查看次数: |
5892 次 |
| 最近记录: |