[PWA] 11. Serve skeleton cache for root
2016-05-18 03:15
134 查看
Intead of cache the root floder, we want to cache skeleton instead.
Respond to requests for the root page with thepage skeleton from the cache:
self.addEventListener('install', function (event) { event.waitUntil( caches.open(staticCacheName).then(function (cache) { return cache.addAll([ '/skeleton', 'js/main.js', 'css/main.css', 'imgs/icon.png', 'https://fonts.gstatic.com/s/roboto/v15/2UX7WLTfW3W8TclTUvlFyQ.woff', 'https://fonts.gstatic.com/s/roboto/v15/d-6IYplOFocCacKzxwXSOD8E0i7KZn-EPnyo3HZu7kw.woff' ]); }) ); });
Respond to requests for the root page with thepage skeleton from the cache:
self.addEventListener('fetch', function (event) { // use the page skeleton from the cache let requestUrl = new URL(event.request.url); if(requestUrl.origin === location.origin){ if(requestUrl.pathname === '/'){ event.respondWith( caches.match('/skeleton') ); return; } } event.respondWith( caches.match(event.request).then(function (response) { return response || fetch(event.request); }) ); });
相关文章推荐
- JAVA网络-URL
- pyqt 代码生成错误
- C语言的指针、链表的原理和各类操作以及学生信息管理系统改进报告
- 【C语言】指针、链表的原理和各类操作相关心得以及学生信息管理系统的改写报告
- Make Notepad++ auto close HTML/XML tags after the slash(the Dreamweaver way)
- Centos7.0配置Hadoop2.6.3单机/伪分布式环境
- NYOJ-18-The Triangle
- Android 制作简易浏览器源码
- 安装boost库(Windows)
- swift版QQ音乐播放器(一)
- VMWare中Linux虚拟机设置静态IP上网的设置方法
- 算法基础 - RMQ-ST算法(在线算法)
- 关于结构体以及宿舍管理系统的设计
- 【C语言】结构体的应用以及学生成绩管理系统的设计
- 友盟分享
- 在多叉树中查找某个节点及其拓展思考
- 正则表达式
- iOS开发 常用的十种数据结构
- 【JAVA】三 【设计模式】一 JAVA 单例 枚举
- Drupal的工作原理