This commit is contained in:
Nolan Lawson
2018-09-07 17:25:17 -07:00
parent 2d1f535314
commit 87ff9c2aeb
2 changed files with 10 additions and 4 deletions

View File

@@ -312,6 +312,7 @@ function get_page_handler(
} = get_build_info();
res.setHeader('Content-Type', 'text/html');
res.setHeader('Cache-Control', dev() ? 'no-cache' : 'max-age=600');
// preload main.js and current route
// TODO detect other stuff we can preload? images, CSS, fonts?
@@ -532,7 +533,6 @@ function get_page_handler(
.replace('%sapper.styles%', () => styles);
res.statusCode = status;
res.setHeader('Cache-Control', dev() ? 'no-cache' : 'max-age=600');
res.end(body);
}).catch(err => {
if (error) {

View File

@@ -5,6 +5,7 @@ const Nightmare = require('nightmare');
const walkSync = require('walk-sync');
const rimraf = require('rimraf');
const ports = require('port-authority');
const fetch = require('node-fetch');
Nightmare.action('page', {
title(done) {
@@ -800,15 +801,20 @@ function run({ mode, basepath = '' }) {
});
describe('headers', () => {
it('sets Content-Type and Link...preload headers', () => {
return capture(() => nightmare.goto(base)).then(requests => {
const { headers } = requests[0];
it('sets Content-Type, Link...preload, and Cache-Control headers', () => {
return capture(() => fetch(base)).then(responses => {
const { headers } = responses[0];
assert.equal(
headers['content-type'],
'text/html'
);
assert.equal(
headers['cache-control'],
'max-age=600'
);
const str = ['main', '.+?\\.\\d+']
.map(file => {
return `<${basepath}/client/[^/]+/${file}\\.js>;rel="preload";as="script"`;