在缓存清单文件 HTML5 的 FALLBACK 部分使用通配符 [英] Using Wildcard in FALLBACK section of Cache manifest file HTML5

查看:24
本文介绍了在缓存清单文件 HTML5 的 FALLBACK 部分使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个支持离线的网络应用程序当用户访问 hxxp://mywebsite/并处于离线状态时,会显示 hxxp://mywebsite/offline/.[我的网站上大约有 100 个不同的动态页面,因此我无法在缓存清单文件中对所有这些页面进行硬编码]

How to create an offline enabled web-application such that when user visits hxxp://mywebsite/ and is offline than hxxp://mywebsite/offline/ is displayed. [There are about 100 different dynamic pages in my website, so I cannot afford to hardcode all of them in the cache manifest file]

推荐答案

CACHE MANIFEST
CACHE:
/Offline/OfflineIndex.html

FALLBACK:
/ /Offline/OfflineIndex.html

NETWORK:
*

这将导致整个网站上的所有页面在离线时重定向到离线.唯一的问题是声明清单的页面,因为该页面总是被缓存.这意味着您不能在每个页面上声明清单,因为每个访问过的页面都将被缓存而不是重定向.因此,您可以做的是在另一个 html 文件(IE.Synchronize.html)上声明您的清单,然后通过存储 cookie 或 localcache 值从默认情况下检查您的应用程序是否已可供离线使用.如果没有使用声明的清单重定向到synchronize.html,则设置localcache 值,然后重定向回索引.

This will cause all your pages across the entire site to redirect to offline when offline. The only issue is with the page that declares the manifest as that page is always cached. This means you cannot declare the manifest on every page because every visited page will then be cached itself and not redirect. So what you can do is declare your manifest on another html file (IE. Synchronize.html) then from default check whether or not your app has been made available for offline by storing a cookie or localcache value. If not redirect to synchronize.html with the manifest declared, set the localcache value, and redirect back to index.

离线真棒SSSSSSSS!!!!

OFFLINE AWESOMENESSSSSSSSSSS!!!!

这篇关于在缓存清单文件 HTML5 的 FALLBACK 部分使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆