Skip to content

Commit

Permalink
fix: remove 4xx response code (like 404) from sw cache
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ccloli committed Jan 23, 2024
1 parent 4505e3d commit 3ae7427
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/app/config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -145,6 +146,7 @@ module.exports = merge(commonConfig, {
maxEntries: 300,
name: 'unpkg-cache',
},
successResponses,
},
},
{
Expand All @@ -155,6 +157,7 @@ module.exports = merge(commonConfig, {
maxEntries: 20,
name: 'cloudflare-cache',
},
successResponses,
},
},
{
Expand All @@ -165,6 +168,7 @@ module.exports = merge(commonConfig, {
maximumFileSizeToCacheInBytes: 1024 * 1024 * 100, // 100mb
name: 'vscode',
},
successResponses,
},
},
{
Expand All @@ -175,6 +179,7 @@ module.exports = merge(commonConfig, {
maximumFileSizeToCacheInBytes: 1024 * 1024 * 100, // 100mb
name: 'vscode-extensions',
},
successResponses,
},
},
],
Expand Down Expand Up @@ -237,6 +242,7 @@ module.exports = merge(commonConfig, {
maxAgeSeconds: 60 * 60 * 24,
name: 'dependency-version-cache',
},
successResponses,
},
},
{
Expand All @@ -250,6 +256,7 @@ module.exports = merge(commonConfig, {
maxAgeSeconds: 60 * 60 * 24,
name: 'static-root-cache',
},
successResponses,
},
},
{
Expand All @@ -261,6 +268,7 @@ module.exports = merge(commonConfig, {
maxAgeSeconds: 60 * 60 * 24 * 7,
name: 'dependency-url-generator-cache',
},
successResponses,
},
},
{
Expand All @@ -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
Expand All @@ -284,6 +293,7 @@ module.exports = merge(commonConfig, {
name: 'unpkg-dep-pkg-cache',
maxAgeSeconds: 60 * 5, // 5 minutes
},
successResponses,
},
},
{
Expand All @@ -295,6 +305,7 @@ module.exports = merge(commonConfig, {
name: 'unpkg-dep-cache',
maxAgeSeconds: 60 * 60 * 24 * 7,
},
successResponses,
},
},
{
Expand All @@ -306,6 +317,7 @@ module.exports = merge(commonConfig, {
name: 'rawgit-cache',
maxAgeSeconds: 60 * 60 * 24 * 7,
},
successResponses,
},
},
{
Expand All @@ -317,6 +329,7 @@ module.exports = merge(commonConfig, {
name: 'jsdelivr-dep-cache',
maxAgeSeconds: 60 * 60 * 24 * 7,
},
successResponses,
},
},
{
Expand All @@ -328,6 +341,7 @@ module.exports = merge(commonConfig, {
name: 'cloudflare-cache',
maxAgeSeconds: 60 * 60 * 24 * 7,
},
successResponses,
},
},
],
Expand Down

0 comments on commit 3ae7427

Please sign in to comment.