[PWA] 4. Hijacking Request
We want to do offline first, the first thing we need to do is we should able to catch the browser request and return our cache data from serice worker. So user won't go to the real server to fetch data. So let's see how to do that:
self.addEventListener('fetch', function(event) {
event.respondWith(
new Response('Hello world');
)
});
We use 'respondWith() and Response()' to provdie a custom cache response.
After you reopen the browser, you will see 'Hello World'.
What if we want to show html instead of pain text? The 'Response()' take a second param which can set header.
self.addEventListener('fetch', function(event) {
event.respondWith(
new Response('Hello <b class="a-winner-is-me">world</b>', {
headers: {'Content-Type': 'text/html'}
});
)
});

[PWA] 4. Hijacking Request的更多相关文章
- [PWA] 5. Hijacking one type of request
Previously we saw how to Hijacking all the reqest, but this is not useful. So now we want to see how ...
- [PWA] 6. Hijacking response
For example, if the url is not match to any API endpoint, we want to return 404 error message. So fi ...
- [Rails] 从 Request 到 Response(1)
本文翻译自:Rails from Request to Response 系列:个人选择了自己感兴趣的部分进行翻译,需要阅读原文的同学请戳前面的链接. 第一部分 导言(Introduction) 服务 ...
- 轻松把你的项目升级到PWA
什么是PWA PWA(Progressive Web Apps,渐进式网页应用)是Google在2015年推出的项目,致力于通过web app获得类似native app体验的网站. 优点 1.无需客 ...
- 前端应该了解的PWA
一.传统web 应用 当前web应用在移动时代并没有达到其在桌面设备上流行的程度,下面有张图来对比与原生应用之间的差别. 究其原因,无外乎下面不可避免的几点: 移动设备网络限制-不可忽略的加载时间 w ...
- 渐进式Web应用(PWA)入门教程(下)
上篇文章我们对渐进式Web应用(PWA)做了一些基本的介绍. 渐进式Web应用(PWA)入门教程(上) 在这一节中,我们将介绍PWA的原理是什么,它是如何开始工作的. 第一步:使用HTTPS 渐进式W ...
- PWA的探索与应用
本文由云+社区发表 PWA(Progressive Web App)起源背景 传统的Web网页存在以下几个问题: 进入一个页面必须要记住它的url或者加入书签,入口不便捷: 没网络就没响应,不具备离线 ...
- 干货 | 10分钟玩转PWA
关于PWA PWA(Progressive Web App), 即渐进式web应用.PWA本质上是web应用,目的是通过多项新技术,在安全.性能.体验等方面给用户原生应用的体验.而且无需像原生应用那样 ...
- H5 PWA技术以及小demo
H5 PWA技术 1.原生app优缺点 a.体验好.下载到手机上入口方便 b.开发成本高(ios和安卓) c.软件上线需要审核 d.版本更新需要将新版本上传到不同的应用商店 e.使用前需下载 2.we ...
随机推荐
- phpcms源码解析(2)
1.程序启动逻辑: 首先由文件\index.php调用create_app(),此函数在文件\phpcms\base.php中,它完成初始化应用程序,调用函数load_sys_class并提供参数ap ...
- HTML 动态显示系统当前时间
HTML 动态显示系统当前时间: <div id="time"> <script> document.getElementById('time').inne ...
- github 分支 合并
Git如何进行分支管理? 1.创建分支 创建分支很简单:git branch <分支名> 2.切换分支 git checkout <分支名&g ...
- [Android1.5]TextView跑马灯效果
from: http://www.cnblogs.com/over140/archive/2010/08/20/1804770.html 前言 这个效果在两周前搜索过,网上倒是有转载,可恨的是转载之后 ...
- python模块之re正则表达式
41.python的正则表达式 1. python中re模块提供了正则表达式相关操作 字符: . 匹配除换行符以外的任意字符 \w 匹配字母或数字或下划线或汉字 \W大写代表非\w ...
- A题 - A + B Problem
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Cal ...
- 转:php的memcache和memcached扩展区别
原文来自于:http://www.cnblogs.com/yjf512/p/3778287.html 作者:叶剑峰 老生长谈的问题了.我这里就整理一下. memcache的文档在:http://pec ...
- 一个用得比较广的微信API的XXE外部实体注入漏洞
文件地址: https://github.com/dodgepudding/wechat-php-sdk/raw/master/wechat.class.php 代码: <?php /** * ...
- 今天写了个从一张表数据插入到另一张表的oracle 语句
create or replace procedure data_move(param in number) is cursor enterprise is select SENTERPRISEID, ...
- 图片的css自适应
当需要css来缩放图片的时候,可以采用外层容器100%或者任意百分比, 内层图片img tag 没有宽高,用sass写经过断点后的mixin中的样式就是这样: .workscon_section{ w ...