3322b91c5d
Even with the caching changes, a 150kB thumbnail still takes 1-2s to fetch. This impacts the score. ## Change (1) Start with a large-enough placeholder image (has to be larger than the final image -- inflating doesn't count), then delay just enough for scoring, then switch to the real thumbnail. (2) Since we are now doing post-mount stuff, we have the exact dimensions to optimize the claim thumbnail. This reduces the typically-several-MBs thumbnail to kBs.
34 lines
922 B
JavaScript
34 lines
922 B
JavaScript
const SIX_MONTHS_IN_SECONDS = 15552000;
|
|
|
|
const STATIC_ASSET_PATHS = [
|
|
'/public/font/font-v1.css',
|
|
'/public/font/v1/300.woff',
|
|
'/public/font/v1/300i.woff',
|
|
'/public/font/v1/400.woff',
|
|
'/public/font/v1/400i.woff',
|
|
'/public/font/v1/700.woff',
|
|
'/public/font/v1/700i.woff',
|
|
'/public/favicon.png',
|
|
'/public/img/busy.gif',
|
|
'/public/img/fileRenderPlaceholder.gif',
|
|
'/public/img/gerbil-happy.png',
|
|
'/public/img/gerbil-sad.png',
|
|
'/public/img/placeholder.png',
|
|
'/public/img/thumbnail-broken.png',
|
|
'/public/img/thumbnail-missing.png',
|
|
'/public/img/total-background.png',
|
|
];
|
|
|
|
async function redirectMiddleware(ctx, next) {
|
|
const {
|
|
request: { url },
|
|
} = ctx;
|
|
|
|
if (STATIC_ASSET_PATHS.includes(url) || (url.startsWith('/public/ui-') && url.endsWith('.js'))) {
|
|
ctx.set('Cache-Control', `public, max-age=${SIX_MONTHS_IN_SECONDS}`);
|
|
}
|
|
|
|
return next();
|
|
}
|
|
|
|
module.exports = redirectMiddleware;
|