|
@@ -10,6 +10,17 @@ module.exports = (app) => { |
|
@@ -10,6 +10,17 @@ module.exports = (app) => { |
10
|
function getStatic(path, def) {
|
10
|
function getStatic(path, def) {
|
11
|
return _.get(manifest, path, `${config.assetUrl}${def}`);
|
11
|
return _.get(manifest, path, `${config.assetUrl}${def}`);
|
12
|
}
|
12
|
}
|
|
|
13
|
+
|
|
|
14
|
+ function getPreloads(list, type) {
|
|
|
15
|
+ let _list = [];
|
|
|
16
|
+
|
|
|
17
|
+ _.forEach(list, url => {
|
|
|
18
|
+ _list.push({url, type});
|
|
|
19
|
+ });
|
|
|
20
|
+
|
|
|
21
|
+ return _list;
|
|
|
22
|
+ }
|
|
|
23
|
+
|
13
|
return (req, res, next) => {
|
24
|
return (req, res, next) => {
|
14
|
res.on('beforeRender', (params) => {
|
25
|
res.on('beforeRender', (params) => {
|
15
|
if (params) {
|
26
|
if (params) {
|
|
@@ -35,7 +46,10 @@ module.exports = (app) => { |
|
@@ -35,7 +46,10 @@ module.exports = (app) => { |
35
|
} else {
|
46
|
} else {
|
36
|
statics.styles.push(getStatic('common.index.css', 'css/index.css'));
|
47
|
statics.styles.push(getStatic('common.index.css', 'css/index.css'));
|
37
|
}
|
48
|
}
|
|
|
49
|
+
|
38
|
res.locals.statics = statics;
|
50
|
res.locals.statics = statics;
|
|
|
51
|
+ res.locals.preloads = _.concat(getPreloads(statics.styles, 'style'),
|
|
|
52
|
+ getPreloads(statics.javascripts, 'script'));
|
39
|
}
|
53
|
}
|
40
|
}
|
54
|
}
|
41
|
});
|
55
|
});
|