The invention relates to a file cache method based on Appcache, including the file cache method: a web browser to access the system, the pre specified page using a manifest file; the use of server-side dynamic web technology in response to the manifest file request, through the cookie first determine whether the browser cache is specified by the manifest resource the file, and then according to the judgment result for the corresponding operation is sent to the browser to the manifest file, the browser receives the manifest file and the file cache. The present invention through the dynamic manifest file with the front end of the JavaScript response to Appcache events can make specific control instructions, achieved by fixed URL and manifest file address out of the cache to specify a part of the resources, simplify the management of the site to speed up resource buffer download speed.
【技术实现步骤摘要】
基于Appcache的文件缓存方法
本专利技术涉及一种缓存技术,具体地说是一种基于Appcache的文件缓存方法。
技术介绍
在计算机和网络迅速发展的现代社会,每个人生活、学习和工作都离不开web应用和数据存储,大量文档和资料数据的缓存是需要重点解决的问题。起初,HTML页面只能通过向服务器访问从而获得页面并展示出来。在W3C的HTML5标准中(https://www.w3.org/TR/html5/),提出了一个新的叫Appcache的机制(又叫OfflineWebApplications:https://www.w3.org/TR/html5/browsers.html#offline),具体的原理就是通过一个manifest文件声明页面有哪些内容需要缓存到浏览器本地,从而当下次浏览器访问到此页面网址的时候,就可以直接使用缓存到浏览器本地的文件,而不用再次请求服务器。并且在浏览器所在的电脑未联网的时候,也可以保证访问声明了manifest文件的网址。Manifest文件的内容分为如下几个区域:CACHE(缓存),此区域中列出所有需要缓存到本地的文件;FALLBACK(回调区域),当浏览器处于离线状态的时候,调用某些文件(网址)时应转而调用其他网址;NETWORK(不缓存区域),列出不应缓存到本地的文件;SETTINGS(设置),列出一些影响Appcache工作的配置项,一般不设置。除此之外,HTML5标准中还引入Appcache对象,用于暴露一些事件和方法,用于通知用户在缓存过程中发生的一系列的动作。从Appcache的引入的机制来看,Appcache ...
【技术保护点】
一种基于Appcache的文件缓存方法,其特征在于,包括:浏览器访问系统的一个网址,预先指定该网页使用某一个manifest文件;服务器端使用动态网页技术响应所述manifest文件请求时,先通过cookie判断浏览器是否缓存了所述manifest文件的指定资源,然后根据判断结果对所述manifest文件进行相应操作后发送至浏览器端,浏览器端接收所述manifest文件并进行文件缓存。
【技术特征摘要】
1.一种基于Appcache的文件缓存方法,其特征在于,包括:浏览器访问系统的一个网址,预先指定该网页使用某一个manifest文件;服务器端使用动态网页技术响应所述manifest文件请求时,先通过cookie判断浏览器是否缓存了所述manifest文件的指定资源,然后根据判断结果对所述manifest文件进行相应操作后发送至浏览器端,浏览器端接收所述manifest文件并进行文件缓存。2.如权利要求1所述的基于Appcache的文件缓存方法,其特征在于,所述相应操作包括:当所述浏览器未缓存过本网站的任何资源时,所述manifest文件直接在cache缓存区列出需要缓存的指定资源的全部文件的URL,浏览器端收到所述manifest文件后,自动开始下载并缓存指定资源,并在cookie中写入缓存资源的ID。3.如权利要求2所述的基于Appcache的文件缓存方法,其特征在于,所述相应操作还包括:当所述浏览器缓存过本网站的其他资源时,所述manifest文件先是直接返回HTTPcode404的响应,并清空cookie中写入资源的ID,浏览器端触发一个error事件并删除原来通过所述manifest文件缓存到本地的资源,程序通过JavaScript部署Appcache的error事件后,通过JavaScript使用iframe再次请求一个引用了所述manifest文件的网页,之后,所述manifest文件直接在c...
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。