1 Star 0 Fork 0

杜宋T/simpl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sw.js 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
Sam Dutton 提交于 2020-07-17 19:22 . Updated sw.js
/*
Copyright 2017 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const FILES = [
'index.html'
];
const CACHE = 'v2.42';
self.addEventListener('install', (event) => {
// console.log('Service worker:', event);
event.waitUntil(installHandler(event));
});
self.addEventListener('activate', (event) => {
// console.log('Service worker:', event);
window.clients.claim();
});
self.addEventListener('fetch', (event) => {
// console.log('Service worker:', event);
event.respondWith(fetchHandler(event.request));
});
async function installHandler(event) {
const cache = await caches.open(CACHE);
cache.addAll(FILES);
self.skipWaiting();
}
async function fetchHandler(request) {
const cache = await caches.open(CACHE);
const cacheResult = await cache.match(request);
if (cacheResult) {
return cacheResult;
}
const fetchResult = await fetch(request);
if (fetchResult.ok) {
cache.put(request, fetchResult.clone());
}
return fetchResult;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dusong7/simpl.git
git@gitee.com:dusong7/simpl.git
dusong7
simpl
simpl
gh-pages

搜索帮助