Files
qihuo/static/sw.js
T
dekun 6d55a54946 Fix turbo nav layout flash and stats page not loading.
Wait for page CSS before swapping content, hoist inline styles to head, and boot page scripts immediately when DOM markers exist.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 20:55:36 +08:00

72 lines
2.2 KiB
JavaScript

/* Copyright (c) 2025-2026 马建军. All rights reserved.
* 专有软件 — 未经授权禁止复制、传播、转售。
* 详见 LICENSE.zh-CN.txt
*/
var CACHE_VERSION = 'qihuo-v7';
var STATIC_CACHE = CACHE_VERSION + '-static';
var STATIC_ASSETS = [
'/static/css/base.css',
'/static/css/tech.css',
'/static/css/responsive.css',
'/static/css/trade.css',
'/static/js/theme.js',
'/static/js/page.js',
'/static/js/nav.js',
'/static/js/turbonav.js',
'/static/js/pwa.js',
'/static/js/symbol.js',
'/static/js/trade.js',
'/static/icons/icon-192.png',
'/static/icons/icon-512.png',
'/static/icons/icon.svg',
'/static/manifest.json',
'/login'
];
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(STATIC_CACHE).then(function (cache) {
return cache.addAll(STATIC_ASSETS).catch(function () { /* ignore partial */ });
}).then(function () { return self.skipWaiting(); })
);
});
self.addEventListener('activate', function (event) {
event.waitUntil(
caches.keys().then(function (keys) {
return Promise.all(keys.filter(function (k) {
return k.startsWith('qihuo-') && k !== STATIC_CACHE;
}).map(function (k) { return caches.delete(k); }));
}).then(function () { return self.clients.claim(); })
);
});
self.addEventListener('fetch', function (event) {
var req = event.request;
if (req.method !== 'GET') return;
var url = new URL(req.url);
if (url.origin !== self.location.origin) return;
if (url.pathname.indexOf('/static/') === 0) {
event.respondWith(
caches.match(req).then(function (cached) {
return cached || fetch(req).then(function (res) {
var copy = res.clone();
caches.open(STATIC_CACHE).then(function (cache) { cache.put(req, copy); });
return res;
});
})
);
return;
}
if (req.mode === 'navigate' || (req.headers.get('accept') || '').indexOf('text/html') !== -1) {
event.respondWith(
fetch(req).catch(function () {
return caches.match('/login');
})
);
}
});