mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 15:15:19 +00:00
Merge pull request #429 from nolanlawson/consistent-cache-control
Use consistent cache-control:max-age=600 for HTML pages
This commit is contained in:
@@ -136,7 +136,7 @@ export default function middleware(opts: {
|
|||||||
|
|
||||||
fs.existsSync(path.join(output, 'index.html')) && serve({
|
fs.existsSync(path.join(output, 'index.html')) && serve({
|
||||||
pathname: '/index.html',
|
pathname: '/index.html',
|
||||||
cache_control: 'max-age=600'
|
cache_control: dev() ? 'no-cache' : 'max-age=600'
|
||||||
}),
|
}),
|
||||||
|
|
||||||
fs.existsSync(path.join(output, 'service-worker.js')) && serve({
|
fs.existsSync(path.join(output, 'service-worker.js')) && serve({
|
||||||
@@ -312,6 +312,7 @@ function get_page_handler(
|
|||||||
} = get_build_info();
|
} = get_build_info();
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'text/html');
|
res.setHeader('Content-Type', 'text/html');
|
||||||
|
res.setHeader('Cache-Control', dev() ? 'no-cache' : 'max-age=600');
|
||||||
|
|
||||||
// preload main.js and current route
|
// preload main.js and current route
|
||||||
// TODO detect other stuff we can preload? images, CSS, fonts?
|
// TODO detect other stuff we can preload? images, CSS, fonts?
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const Nightmare = require('nightmare');
|
|||||||
const walkSync = require('walk-sync');
|
const walkSync = require('walk-sync');
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
const ports = require('port-authority');
|
const ports = require('port-authority');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
Nightmare.action('page', {
|
Nightmare.action('page', {
|
||||||
title(done) {
|
title(done) {
|
||||||
@@ -800,15 +801,20 @@ function run({ mode, basepath = '' }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
it('sets Content-Type and Link...preload headers', () => {
|
it('sets Content-Type, Link...preload, and Cache-Control headers', () => {
|
||||||
return capture(() => nightmare.goto(base)).then(requests => {
|
return capture(() => fetch(base)).then(responses => {
|
||||||
const { headers } = requests[0];
|
const { headers } = responses[0];
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
headers['content-type'],
|
headers['content-type'],
|
||||||
'text/html'
|
'text/html'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
headers['cache-control'],
|
||||||
|
'max-age=600'
|
||||||
|
);
|
||||||
|
|
||||||
const str = ['main', '.+?\\.\\d+']
|
const str = ['main', '.+?\\.\\d+']
|
||||||
.map(file => {
|
.map(file => {
|
||||||
return `<${basepath}/client/[^/]+/${file}\\.js>;rel="preload";as="script"`;
|
return `<${basepath}/client/[^/]+/${file}\\.js>;rel="preload";as="script"`;
|
||||||
|
|||||||
Reference in New Issue
Block a user