Authored by 陈峰

Merge branch 'hotfix/workbox' into 'release/9.19'

Hotfix/workbox

workbox plugin & statics preload

See merge request !1542
... ... @@ -68,7 +68,7 @@ exports.bottombar = function(req, res, next) {
exports.couponSend = (req, res, next) => {
let token = req.query.token || '',
uid = req.user.uid,
app = req.query.app;
app = req.query.app || {};
let resultData = {
code: 403,
... ...
... ... @@ -13,5 +13,6 @@ module.exports = new InjectManifest({
`https://cdn.yoho.cn/workbox/workbox-core.${suffix}.js`,
`https://cdn.yoho.cn/workbox/workbox-precaching.${suffix}.js`,
`https://cdn.yoho.cn/workbox/workbox-routing.${suffix}.js`,
`https://cdn.yoho.cn/workbox/workbox-cache-expiration.${suffix}.js`]
`https://cdn.yoho.cn/workbox/workbox-cache-expiration.${suffix}.js`,
`https://cdn.yoho.cn/workbox/workbox-strategies.${suffix}.js`]
});
... ...
... ... @@ -10,6 +10,17 @@ module.exports = (app) => {
function getStatic(path, def) {
return _.get(manifest, path, `${config.assetUrl}${def}`);
}
function getPreloads(list, type, cross) {
let _list = [];
_.forEach(list, url => {
_list.push({url, type, cross});
});
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', true));
}
}
});
... ...
... ... @@ -24,6 +24,10 @@
<link rel="dns-prefetch" href="{{this}}">
{{/dnsPrefetch.hosts}}
{{#preloads}}
<link rel="preload" href="{{url}}" as="{{type}}" {{#if cross}}crossorigin="anonymous"{{/if}}>
{{/preloads}}
<script>
{{#ifand isProduction wap.open.bughd}}
window._timeStart = new Date().getTime();
... ...