2f5b5c4aae
Reduce poll pressure on phone/tablet, cache key prices, and handle live API errors gracefully. Rework mobile position and close cards with inline direction, compact P/L line, and detail modal. Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
/* Copyright (c) 2025-2026 马建军. All rights reserved.
|
|
* 专有软件 — 未经授权禁止复制、传播、转售。
|
|
* 详见 LICENSE.zh-CN.txt
|
|
*/
|
|
var CACHE_VERSION = 'qihuo-v10';
|
|
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/nav.js',
|
|
'/static/js/pwa.js',
|
|
'/static/js/symbol.js',
|
|
'/static/js/trade.js',
|
|
'/static/js/stats.js',
|
|
'/static/js/settings.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');
|
|
})
|
|
);
|
|
}
|
|
});
|