lbry-desktop/web/middleware/cache-control.js
infinite-persistence 6f4ce0a57c
Apply placeholder images
https://lbryians.slack.com/archives/C81FGKR51/p1624278721203900?thread_ts=1624269131.202200&cid=C81FGKR51

The intrinsic size needs to be at least equal the final image's size. Stretching, SVGs, etc. doesn't count.
2021-07-19 12:07:26 +08:00

35 lines
957 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.png',
'/public/img/gerbil-happy.png',
'/public/img/gerbil-sad.png',
'/public/img/placeholder.png',
'/public/img/placeholderTx.gif',
'/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;