Merge pull request #530 from artemjackson/patch-1

Fixed rel="preload" `as` attribute for styles
This commit is contained in:
Rich Harris
2018-12-09 10:28:39 -05:00
committed by GitHub

View File

@@ -67,7 +67,10 @@ export function get_page_handler(
} else {
const link = preloaded_chunks
.filter(file => file && !file.match(/\.map$/))
.map(file => `<${req.baseUrl}/client/${file}>;rel="preload";as="script"`)
.map((file) => {
const as = /\.css$/.test(file) ? 'style' : 'script';
return `<${req.baseUrl}/client/${file}>;rel="preload";as="${as}"`;
})
.join(', ');
res.setHeader('Link', link);
@@ -335,4 +338,4 @@ function escape_html(html: string) {
};
return html.replace(/["'&<>]/g, c => `&${chars[c]};`);
}
}