Authored by yyq

statics preload

... ... @@ -10,6 +10,17 @@ module.exports = (app) => {
function getStatic(path, def) {
return _.get(manifest, path, `${config.assetUrl}${def}`);
}
function getPreloads(list, type) {
let _list = [];
_.forEach(list, url => {
_list.push({url, type});
});
return _list;
}
return (req, res, next) => {
res.on('beforeRender', (params) => {
if (params) {
... ... @@ -35,7 +46,10 @@ module.exports = (app) => {
} else {
statics.styles.push(getStatic('common.index.css', 'css/index.css'));
}
res.locals.statics = statics;
res.locals.preloads = _.concat(getPreloads(statics.styles, 'style'),
getPreloads(statics.javascripts, 'script'));
}
}
});
... ...
... ... @@ -24,6 +24,10 @@
<link rel="dns-prefetch" href="{{this}}">
{{/dnsPrefetch.hosts}}
{{#preloads}}
<link rel="preload" href="{{url}}" as="{{type}}">
{{/preloads}}
<script>
{{#ifand isProduction wap.open.bughd}}
window._timeStart = new Date().getTime();
... ...