HTML5 应用程序缓存(Application Cache)
HTML5 应用程序缓存(Application Cache)
1.应用程序缓存(Application Cache):
通过使用manifest并配置文件列表
应用程序缓存为应用带来三个优势:
•离线浏览 - 用户可在应用离线时使用它们
•速度 - 已缓存资源加载得更快
•减少服务器负载 - 浏览器将只从服务器下载更新过或更改过的资源。
2.如何实现
2.1服务器配置步骤如下:
在服务器上添加MIME TYPE支比如 Apache 中可在 .htaccess 中添加:AddType text/cache-manifest manifest
2.2创建Manifest 文件
manifest 文件是简单的文本文件,它告知浏览器被缓存的内容(以及不缓存的内容)。
manifest 文件可分为三个部分:
l CACHE MANIFEST - 在此标题下列出的文件将在首次下载后进行缓存
l NETWORK - 在此标题下列出的文件需要与服务器的连接,且不会被缓存
l FALLBACK - 在此标题下列出的文件规定当页面无法访问时的回退页面(比如 404 页面)
CACHE MANIFEST
第一行,CACHE MANIFEST,是必需的:
2.2.1CACHE MANIFEST
/theme.css
/logo.gif
/main.js
上面的 manifest 文件列出了三个资源:一个 CSS 文件,一个 GIF 图像,以及一个 JavaScript 文件。当 manifest 文件加载后,浏览器会从网站的根目录下载这三个文件。然后,无论用户何时与因特网断开连接,这些资源依然是可用的。
2.2.2NETWORK
下面的 NETWORK 小节规定文件 "login.asp" 永远不会被缓存,且离线时是不可用的:
NETWORK:
login.asp
可以使用星号来指示所有其他其他资源/文件都需要因特网连接:
NETWORK:
*
2.2.3FALLBACK
下面的 FALLBACK 小节规定如果无法建立因特网连接,则用 "offline.html" 替代 /html5/ 目录中的所有文件:
FALLBACK:
/html5/ /404.html
3.更新缓存
一旦应用被缓存,它就会保持缓存直到发生下列情况:
l 用户清空浏览器缓存
l manifest 文件被修改
l 由程序来更新应用缓存
4.Chrome浏览器来测试缓存是否成功
在Chorme浏览器中输入缓存页面的网址
使用Chrome的chrome://cache/命令查看
以上就是HTML5 应用程序缓存(Application Cache)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
