From 3ae7427c4bbdb5bcc6a24e9a4b7295c815575875 Mon Sep 17 00:00:00 2001 From: ccloli <8115912+ccloli@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:55:45 +0800 Subject: [PATCH] fix: remove 4xx response code (like 404) from sw cache In case the service gateway got failed and returns a 4xx error code other than 5xx, or a package is published just now but not cached --- packages/app/config/webpack.prod.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/app/config/webpack.prod.js b/packages/app/config/webpack.prod.js index 6f0ef2fd80f..53243702c08 100644 --- a/packages/app/config/webpack.prod.js +++ b/packages/app/config/webpack.prod.js @@ -22,6 +22,7 @@ const publicPath = '/'; // .trim() === 'master'; const normalize = normalizeName({ name: true, automaticNameDelimiter: '~' }); +const successResponses = /^0|([123]\d\d)$/; module.exports = merge(commonConfig, { devtool: 'source-map', @@ -145,6 +146,7 @@ module.exports = merge(commonConfig, { maxEntries: 300, name: 'unpkg-cache', }, + successResponses, }, }, { @@ -155,6 +157,7 @@ module.exports = merge(commonConfig, { maxEntries: 20, name: 'cloudflare-cache', }, + successResponses, }, }, { @@ -165,6 +168,7 @@ module.exports = merge(commonConfig, { maximumFileSizeToCacheInBytes: 1024 * 1024 * 100, // 100mb name: 'vscode', }, + successResponses, }, }, { @@ -175,6 +179,7 @@ module.exports = merge(commonConfig, { maximumFileSizeToCacheInBytes: 1024 * 1024 * 100, // 100mb name: 'vscode-extensions', }, + successResponses, }, }, ], @@ -237,6 +242,7 @@ module.exports = merge(commonConfig, { maxAgeSeconds: 60 * 60 * 24, name: 'dependency-version-cache', }, + successResponses, }, }, { @@ -250,6 +256,7 @@ module.exports = merge(commonConfig, { maxAgeSeconds: 60 * 60 * 24, name: 'static-root-cache', }, + successResponses, }, }, { @@ -261,6 +268,7 @@ module.exports = merge(commonConfig, { maxAgeSeconds: 60 * 60 * 24 * 7, name: 'dependency-url-generator-cache', }, + successResponses, }, }, { @@ -272,6 +280,7 @@ module.exports = merge(commonConfig, { maxAgeSeconds: 60 * 60 * 24 * 7, name: 'dependency-files-cache', }, + successResponses, }, }, // We resolve `package.json` to resolve versions (e.g. next -> 15.0.5). We need to have a much shorter cache on this @@ -284,6 +293,7 @@ module.exports = merge(commonConfig, { name: 'unpkg-dep-pkg-cache', maxAgeSeconds: 60 * 5, // 5 minutes }, + successResponses, }, }, { @@ -295,6 +305,7 @@ module.exports = merge(commonConfig, { name: 'unpkg-dep-cache', maxAgeSeconds: 60 * 60 * 24 * 7, }, + successResponses, }, }, { @@ -306,6 +317,7 @@ module.exports = merge(commonConfig, { name: 'rawgit-cache', maxAgeSeconds: 60 * 60 * 24 * 7, }, + successResponses, }, }, { @@ -317,6 +329,7 @@ module.exports = merge(commonConfig, { name: 'jsdelivr-dep-cache', maxAgeSeconds: 60 * 60 * 24 * 7, }, + successResponses, }, }, { @@ -328,6 +341,7 @@ module.exports = merge(commonConfig, { name: 'cloudflare-cache', maxAgeSeconds: 60 * 60 * 24 * 7, }, + successResponses, }, }, ],