add preload header for main.js and current route - fixes #2

This commit is contained in:
Rich Harris
2017-12-20 18:04:11 -05:00
parent 8d40992cf1
commit 492f024d2a
2 changed files with 14 additions and 5 deletions

View File

@@ -14,8 +14,6 @@ const escape_html = require('escape-html');
const { src, dest, dev } = require('./config.js');
function connect_dev() {
// create main.js and server-routes.js
// TODO update on changes
create_app();
const watcher = create_watcher();
@@ -137,6 +135,10 @@ function get_route_handler(fn) {
const mod = require(server.entry)[route.id];
if (route.type === 'page') {
// preload main.js and current route
// TODO detect other stuff we can preload? images, CSS, fonts?
res.set('Link', `<${client.main_file}>;rel="preload";as="script", <${client.routes[route.id]}>;rel="preload";as="script"`);
let data = { params: req.params, query: req.query };
if (mod.preload) data = Object.assign(data, await mod.preload(data));