[PWA] 4. Hijacking Request
request pwa
2023-09-14 08:59:20 时间
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'} }); ) });
相关文章
- HikariPool-1 – Connection is not available, request timed out after 30000ms.
- Request转发---应用
- Required request body is missing:415
- 浅谈Tomcat之Servlet-request获取请求参数及常用方法
- Request Smuggling Via HTTP/2 Cleartext
- Uncaught (in promise) PushError: permission request declined
- ORA-39017: Worker request not supported when job is in string state. ORACLE 报错 故障修复 远程处理
- ORA-44808: Work Request Class name is too large ORACLE 报错 故障修复 远程处理
- MySQL Error number: 3825; Symbol: ER_INVALID_ENCRYPTION_REQUEST; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-02771: Illegal request time out value ORACLE 报错 故障修复 远程处理
- ORA-12529: TNS:connect request rejected based on current filtering rules ORACLE 报错 故障修复 远程处理
- ORA-16526: unable to allocate memory to process request ORACLE 报错 故障修复 远程处理
- struts2获取request、session、application的四种方式详解编程语言
- JSP Request.isRequestedSessionIdFromURL()方法:判断session ID是否从URL中获得
- JSP Request.setAttribute()方法:设置request对象的属性
- JSP requestScope对象:访问request作用域范围的隐含对象
- Javascript-HTML的request类
- 基于request.getAttribute与request.getParameter的区别详解
- PHP_SELF,SCRIPT_NAME,REQUEST_URI区别