mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 13:35:08 +00:00
Merge pull request #35 from sveltejs/gh-2
add preload header for main.js and current route
This commit is contained in:
@@ -14,8 +14,6 @@ const escape_html = require('escape-html');
|
|||||||
const { src, dest, dev } = require('./config.js');
|
const { src, dest, dev } = require('./config.js');
|
||||||
|
|
||||||
function connect_dev() {
|
function connect_dev() {
|
||||||
// create main.js and server-routes.js
|
|
||||||
// TODO update on changes
|
|
||||||
create_app();
|
create_app();
|
||||||
|
|
||||||
const watcher = create_watcher();
|
const watcher = create_watcher();
|
||||||
@@ -137,6 +135,10 @@ function get_route_handler(fn) {
|
|||||||
const mod = require(server.entry)[route.id];
|
const mod = require(server.entry)[route.id];
|
||||||
|
|
||||||
if (route.type === 'page') {
|
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 };
|
let data = { params: req.params, query: req.query };
|
||||||
if (mod.preload) data = Object.assign(data, await mod.preload(data));
|
if (mod.preload) data = Object.assign(data, await mod.preload(data));
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ const templates = require('../templates.js');
|
|||||||
const route_manager = require('../route_manager.js');
|
const route_manager = require('../route_manager.js');
|
||||||
const { dest } = require('../config.js');
|
const { dest } = require('../config.js');
|
||||||
|
|
||||||
|
function ensure_array(thing) {
|
||||||
|
return Array.isArray(thing) ? thing : [thing]; // omg webpack what the HELL are you doing
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function generate_asset_cache(clientInfo, serverInfo) {
|
module.exports = function generate_asset_cache(clientInfo, serverInfo) {
|
||||||
let main_file = Array.isArray(clientInfo.assetsByChunkName.main) ?
|
const main_file = `/client/${ensure_array(clientInfo.assetsByChunkName.main)[0]}`;
|
||||||
`/client/${clientInfo.assetsByChunkName.main[0]}` : // omg webpack what the HELL are you doing
|
|
||||||
`/client/${clientInfo.assetsByChunkName.main}`;
|
|
||||||
|
|
||||||
const chunk_files = clientInfo.assets.map(chunk => `/client/${chunk.name}`);
|
const chunk_files = clientInfo.assets.map(chunk => `/client/${chunk.name}`);
|
||||||
|
|
||||||
@@ -29,6 +31,11 @@ module.exports = function generate_asset_cache(clientInfo, serverInfo) {
|
|||||||
return lookup;
|
return lookup;
|
||||||
}, {}),
|
}, {}),
|
||||||
|
|
||||||
|
routes: route_manager.routes.reduce((lookup, route) => {
|
||||||
|
lookup[route.id] = `/client/${ensure_array(clientInfo.assetsByChunkName[route.id])[0]}`;
|
||||||
|
return lookup;
|
||||||
|
}, {}),
|
||||||
|
|
||||||
index,
|
index,
|
||||||
service_worker
|
service_worker
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user