HTML 5 오프라인 캐 시
HTML5 응용 프로그램 캐 시 는 오프라인 캐 시 라 고도 부 릅 니 다. 끊 겨 도 새로 고침 후에 원래 페이지 를 캐 시 합 니 다. 404 가 되 지 않 습 니 다.
우선, 문서 의 < html > 탭 에 manifest 속성 을 포함 하 십시오:
<!DOCTYPE HTML>
<html manifest="page.appcache"> <!-- page.appcache , -->
...
</html>
Apache 나. htaccess 파일 에 추가 하기
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|views|plugins|backup|upload|image|runtime|install)
RewriteRule ^(.*)$ index.php/$1 [L]
#
AddType text/cache-manifest manifest
</IfModule>
다음은. appcache 파일 생 성 입 니 다.격식
CACHE MANIFEST
# 2012-02-21 v1.0.0
/theme.css
/logo.gif
/main.js
NETWORK:
login.php
FALLBACK:
/html/ /offline.html
그러나 한 항목 에 이 정도 의 파일 만 있 는 것 이 아니 라 더 많은 자원 파일 을...css. js. img 등 을 불 러 오기 때문에 디 렉 터 리 를 옮 겨 다 니 는 방법 이 필요 합 니 다.다음은 내 가 고 쳐 쓴 방법 이다.
<?php
/**
*
* @param string $folder
* @param int $levels
* @return array
* @author lixianghui
*/
function list_files($folder = '', $levels = 100) { if (empty($folder) || !$levels) { return false; } $files = array(); // if ($dir = @opendir($folder)) { // while (($file = readdir($dir) ) !== false) { // if (in_array($file, array('.', '..'))) continue; // if (preg_match("/[\x7f-\xff]/", $file)) continue; // if (is_dir($folder . '/' . $file)) { // $files2 = list_files($folder . '/' . $file, $levels - 1); // if ($files2) $files = array_merge($files, $files2); else $files[] = $folder . '/' . $file . '/'; } else { // // if (in_array(pathinfo($file)['extension'], array('css', 'js', 'png', 'jpg', 'gif'))) { $files[] = $folder . '/' . $file; } } } } @closedir($dir); return $files; } /** * * @return void * @author lixianghui */ function offline_cache(){ $list = array(); $file_str = "";
// $dir_upload = list_files('upload'); $dir_default = list_files('views/default'); $file_array=array_merge($dir_upload,$dir_default); foreach ($file_array as $val) { $file_str.=$val . "
"; } // appcache $cache_str = "CACHE MANIFEST
"; $cache_str.="#" . date("Y-m-d H:i:s") . "
"; $cache_str.=$file_str; $cache_str.="NETWORK:
"; $cache_str.="FALLBACK:
nomore.html"; file_put_contents("page.appcache", $cache_str); }
자, 이제 콘 솔 테스트 를 열 면 캐 시 자원 이 모두 불 러 오 는 것 을 볼 수 있 습 니 다.저장 이 나타 나 면 자원 이 저장 되 었 는 지, 존재 하 는 지 확인 하 십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.