Authored by 徐炜

DNS 预读配置

  1 +module.exports = {
  2 + hosts: [
  3 + '//cdn.yoho.cn',
  4 + '//static.yohobuy.com',
  5 + '//img10.static.yhbimg.com',
  6 + '//img11.static.yhbimg.com',
  7 + '//img12.static.yhbimg.com',
  8 + '//img13.static.yhbimg.com',
  9 + '//analytics.m.yohobuy.com',
  10 + ]
  11 +};
  12 +
1 'use strict'; 1 'use strict';
2 2
3 const fs = require('fs'); 3 const fs = require('fs');
  4 +const dnsPrefetch = require('../../config/dns-prefetch');
  5 +
4 let devHost = '127.0.0.1'; 6 let devHost = '127.0.0.1';
5 7
6 fs.readFile('.devhost', (err, buf)=> { 8 fs.readFile('.devhost', (err, buf)=> {
@@ -12,7 +14,8 @@ fs.readFile('.devhost', (err, buf)=> { @@ -12,7 +14,8 @@ fs.readFile('.devhost', (err, buf)=> {
12 module.exports = () => { 14 module.exports = () => {
13 return (req, res, next) => { 15 return (req, res, next) => {
14 Object.assign(res.locals, { 16 Object.assign(res.locals, {
15 - devHost: devHost 17 + devHost: devHost,
  18 + dnsPrefetch: dnsPrefetch
16 }); 19 });
17 20
18 next(); 21 next();
@@ -10,10 +10,9 @@ @@ -10,10 +10,9 @@
10 <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 10 <meta name="apple-mobile-web-app-status-bar-style" content="black" />
11 <meta content="telephone=no" name="format-detection" /> 11 <meta content="telephone=no" name="format-detection" />
12 <meta content="email=no" name="format-detection" /> 12 <meta content="email=no" name="format-detection" />
13 - <link rel="dns-prefetch" href="//cdn.yoho.cn">  
14 - <link rel="dns-prefetch" href="//static.yohobuy.com">  
15 - <link rel="dns-prefetch" href="//img12.static.yhbimg.com">  
16 - <link rel="dns-prefetch" href="//img13.static.yhbimg.com"> 13 + {{#dnsPrefetch.hosts}}
  14 + <link rel="dns-prefetch" href="{{this}}">
  15 + {{/dnsPrefetch.hosts}}
17 16
18 <script type="text/javascript"> 17 <script type="text/javascript">
19 var isWechat = /micromessenger/i.test(navigator.userAgent || ''); 18 var isWechat = /micromessenger/i.test(navigator.userAgent || '');