Fixed rel="preload" as attribute for styles

This commit is contained in:
Artyom Stepanishchev
2018-12-07 23:59:51 +03:00
committed by GitHub
parent 14e809af6e
commit 8ebfcc9a54

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]};`);
}
}