Skip to content

Commit f793ec5

Browse files
committed
server-side Clear-Site-Data in response to ?nocache
1 parent c79c3db commit f793ec5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/server.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,24 @@ app.get([
254254
});
255255

256256
app.get('*', (req, res, next) => {
257-
// Ask browsers to revalidate all files that aren't explicitly cached
257+
// If file didn't explicitly get a cache header added, default to requiring revalidation
258258
if (res.getHeader('Cache-Control') === undefined) {
259259
res.setHeader('Cache-Control', 'no-cache');
260260
}
261261
next();
262262
});
263263

264+
app.get('*', (req, res, next) => {
265+
// Errors while loading the initial webpack bundles will offer a link that adds ?nocache=random
266+
// and refreshes. We'll tell the browser to actually delete the caches in this case too to increase
267+
// likelihood of success.
268+
if (req.query.nocache) {
269+
res.setHeader('Clear-Site-Data', '"cache"');
270+
}
271+
272+
next();
273+
});
274+
264275
app.get('/*', asyncHandler(async (req, res, next) => {
265276
let pathName = req.path;
266277
let projectId = null;

0 commit comments

Comments
 (0)