mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Made Admin assets aggressively cacheable
closes https://github.com/TryGhost/Toolbox/issues/372 - The admin assets are served with a unique hash depending on the build with a year-long "max-age" value in the response cache-control header. The client browsers still do send 'If-None-Match' requests when there is a hard-refresh on the client side. There's no need for 'If-None-Match' requests though! - With 'immutable' value in the cache-control header, the browser caches are treating responses as "hard-fresh" without sending redundant requests. - For more about 'immutable' value read https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#immutable
This commit is contained in:
parent
fe90dde0e1
commit
225a046bb8
3 changed files with 10 additions and 3 deletions
|
@ -17,9 +17,15 @@ module.exports = function setupAdminApp() {
|
|||
// Admin assets
|
||||
// @TODO ensure this gets a local 404 error handler
|
||||
const configMaxAge = config.get('caching:admin:maxAge');
|
||||
// @NOTE: when we start working on HTTP/3 optimizations the immutable headers
|
||||
// produced below should be split into separate 'Cache-Control' entry.
|
||||
// For reference see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching#validation_2
|
||||
adminApp.use('/assets', serveStatic(
|
||||
path.join(config.get('paths').adminAssets, 'assets'),
|
||||
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.ONE_YEAR_MS, fallthrough: false}
|
||||
path.join(config.get('paths').adminAssets, 'assets'), {
|
||||
maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.ONE_YEAR_MS,
|
||||
immutable: true,
|
||||
fallthrough: false
|
||||
}
|
||||
));
|
||||
|
||||
adminApp.use('/auth-frame', serveStatic(
|
||||
|
|
|
@ -38,7 +38,7 @@ describe('Admin Routing', function () {
|
|||
|
||||
it('should retrieve built assets', async function () {
|
||||
await request.get('/ghost/assets/vendor.js')
|
||||
.expect('Cache-Control', testUtils.cacheRules.year)
|
||||
.expect('Cache-Control', testUtils.cacheRules.yearImmutable)
|
||||
.expect(200)
|
||||
.expect(assertCorrectHeaders);
|
||||
});
|
||||
|
|
|
@ -3,5 +3,6 @@ module.exports = {
|
|||
hour: 'public, max-age=' + 3600,
|
||||
day: 'public, max-age=' + 86400,
|
||||
year: 'public, max-age=' + 31536000,
|
||||
yearImmutable: 'public, max-age=' + 31536000 + ', immutable',
|
||||
private: 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue