forked from baron/baron-sso
fix(userfront): reduce service worker install cache
This commit is contained in:
@@ -105,7 +105,8 @@ if (existsSync(indexPath)) {
|
||||
let index = readFileSync(indexPath, 'utf8');
|
||||
const preloadLinks = [
|
||||
'<link rel="preload" href="flutter_bootstrap.js" as="script" />',
|
||||
hashedEntrypoints.has('main.dart.js')
|
||||
hashedEntrypoints.has('main.dart.js') &&
|
||||
!(hashedEntrypoints.has('main.dart.mjs') && hashedEntrypoints.has('main.dart.wasm'))
|
||||
? `<link rel="preload" href="${hashedEntrypoints.get('main.dart.js')}" as="script" />`
|
||||
: '',
|
||||
hashedEntrypoints.has('main.dart.mjs')
|
||||
@@ -209,6 +210,10 @@ function createServiceWorker() {
|
||||
}
|
||||
|
||||
const assetPath = `/${relative(buildDir, filePath).replaceAll('\\', '/')}`;
|
||||
if (!shouldPrecacheAsset(assetPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assets.push(assetPath);
|
||||
versionHash.update(assetPath);
|
||||
versionHash.update(readFileSync(filePath));
|
||||
@@ -305,6 +310,27 @@ async function cacheFirst(request) {
|
||||
`;
|
||||
}
|
||||
|
||||
function shouldPrecacheAsset(assetPath) {
|
||||
if (
|
||||
[
|
||||
'/index.html',
|
||||
'/flutter_bootstrap.js',
|
||||
'/manifest.json',
|
||||
'/version.json',
|
||||
'/assets/AssetManifest.bin.json',
|
||||
'/assets/FontManifest.json',
|
||||
].includes(assetPath)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (/^\/assets\/assets\/translations\/(?:en|ko|template)\.toml$/.test(assetPath)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function ensureServiceWorkerUrl(settings) {
|
||||
const serviceWorkerUrl = `"/flutter_service_worker.js?v=" + ${serviceWorkerVersionExpression(settings)}`;
|
||||
if (/serviceWorkerUrl\s*:/.test(settings)) {
|
||||
|
||||
Reference in New Issue
Block a user