[PWA] 6. Hijacking response
For example, if the url is not match to any API endpoint, we want to return 404 error message.
So first thing, we want to send the request to the server first. If got the response, then we just return it back.
self.addEventListener('fetch', (event) => {
event.respondWith(
fetch(event.request).then( (response) => {
// fetch the request frist
return response;
})
)
});
Then we handle 404 error:
self.addEventListener('fetch', (event) => {
event.respondWith(
fetch(event.request).then( (response) => {
if(response.status === ){
return fetch('/img/dr-evil.gif');
}
return response;
}).catch( () => {
return new Response("Something totally wrong");
})
)
});
[PWA] 6. Hijacking response的更多相关文章
- [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] 4. Hijacking Request
We want to do offline first, the first thing we need to do is we should able to catch the browser re ...
- HTTP Response Splitting攻击探究 <转>
第一小节:HTTP Basics:使用Proxy软件(例如Webscarab)来截断浏览器(客户端)和Server之间的HTTP通信,之后任意篡改得到预期结果即可. 第二小节:HTTP Splitti ...
- [Rails] 从 Request 到 Response(1)
本文翻译自:Rails from Request to Response 系列:个人选择了自己感兴趣的部分进行翻译,需要阅读原文的同学请戳前面的链接. 第一部分 导言(Introduction) 服务 ...
- 轻松把你的项目升级到PWA
什么是PWA PWA(Progressive Web Apps,渐进式网页应用)是Google在2015年推出的项目,致力于通过web app获得类似native app体验的网站. 优点 1.无需客 ...
- Angular 学习笔记 ( PWA + App Shell )
PWA (Progressive Web Apps) 是未来网页设计的方向. 渐进式网站. Angular v5 开始支持 pwa 网站 (所谓支持意思是说有一些 build in 的方法和规范去实现 ...
- 前端应该了解的PWA
一.传统web 应用 当前web应用在移动时代并没有达到其在桌面设备上流行的程度,下面有张图来对比与原生应用之间的差别. 究其原因,无外乎下面不可避免的几点: 移动设备网络限制-不可忽略的加载时间 w ...
- 渐进式Web应用(PWA)入门教程(下)
上篇文章我们对渐进式Web应用(PWA)做了一些基本的介绍. 渐进式Web应用(PWA)入门教程(上) 在这一节中,我们将介绍PWA的原理是什么,它是如何开始工作的. 第一步:使用HTTPS 渐进式W ...
- 为 VUE 项目添加 PWA 解决发布后刷新报错问题
为什么要给 VUE 项目添加 PWA 为什么要添加?因为不管是部署在 IIS,还是 nginx,每次应用部署后,再次访问因为旧的 js 已经不存在,所以页面访问的时候会整个报错,报错的结果就是一个白屏 ...
随机推荐
- TextView控件
1.手动创建(不建议): TextView tv = new TextView(this); tv.setContent("你好"); setContentView(tv); 2. ...
- java的动态绑定与双分派(规避instanceof)
1. 动态绑定的概念 指程执行期间(而不是在编译期间)判断所引用对象的实际类型,根据其实际的类型调用其相应的方法 . 例如: package org.demo.clone.demo; public c ...
- LNMP安装WordPress3.4.2看不到主题解决方法
喜欢LNMP配置环境的朋友,又是wordpress建立的博客程序,安装之后发现一个问题在网站后台看不到模板主题,重新下载了一款新的主题也查看不了.开始以为是程序的问题,于是我重新下载新版本的WordP ...
- js转换/Date(........)/
eval('new ' + (datetime.replace(/\//g, ''))); 好记性不如烂笔头,记下以备后用.
- [翻译]jQuery十周年-John Resig
10th Anniversary of jQuery Today marks the 10th anniversary of the release of jQuery...[原文] 今天是jQuer ...
- Centos6.2_(64位)服务器环境配置:源码编译Nginx
目标软件都指定安装目录:/apps.由于Nginx可以使用正则表达式来匹配访问路径, 要正常使用此功能就保证安装有Pcre库,如果你已经接着上一篇操作过来,就可以不用考虑这一点,因为此库已经在安装列表 ...
- UIDevice-b
typedef NS_ENUM(NSInteger, UIDeviceOrientation) //设备方向 { UIDeviceOrientationUnknown, UIDeviceOrienta ...
- 酷炫地给py代码标上行数
Python IDLE是没有显示行号的功能的,今天学了一个方式可以酷炫地给自己的代码加上行号,该方法直接修改代码,慎用哦!代码如下: import fileinput for line in file ...
- Node.js Express框架
Express 介绍 Express是一个最小的,灵活的Node.js Web应用程序框架,它提供了一套强大的功能来开发Web和移动应用程序. 它有助于基于Node Web应用程序的快速开发.下面是一 ...
- optimize performance
http://www.cnblogs.com/fullhouse/archive/2012/01/05/2313105.html http://www.cnblogs.com/fullhouse/ar ...