Skip to content

Commit 8ae1ab6

Browse files
committed
Add caching for more hot paths
1 parent 6cfdb30 commit 8ae1ab6

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/server.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,29 @@ app.get('/users/:user', (req, res) => {
228228
res.send(userPageFile);
229229
});
230230

231-
app.get('*/js/*', (req, res, next) => {
231+
// These files' names contain a hash of their content, so they can be cached forever.
232+
app.get([
233+
'*/js/*',
234+
'*/static/assets/*'
235+
], (req, res, next) => {
232236
// File names contain hash of content, can cache forever.
233237
res.header('Cache-Control', 'public, max-age=315360000, immutable');
234238
next();
235239
});
236-
app.get('*/static/assets/*', (req, res, next) => {
237-
// File names contain hash of content, can cache forever.
238-
res.header('Cache-Control', 'public, max-age=315360000, immutable');
239-
next();
240-
});
241-
app.get('*/static/blocks-media/*', (req, res, next) => {
242-
// File names don't contain hash of content, but these files are hot and will rarely change.
240+
241+
// These files could change but they are reasonably hot and very rarely will change
242+
app.get([
243+
'*/static/blocks-media/*',
244+
'*/favicon.ico',
245+
'*/manifest.webmanifest',
246+
'*/images/*',
247+
// Our sw.js is just a stub; if we actually used it then we would want to not list it here
248+
'*/sw.js'
249+
], (req, res, next) => {
243250
res.header('Cache-Control', 'public, max-age=604800, immutable');
244251
next();
245252
});
253+
246254
app.get('*', (req, res, next) => {
247255
// Ask browsers to revalidate all files that aren't explicitly cached
248256
if (res.getHeader('Cache-Control') === undefined) {

0 commit comments

Comments
 (0)