浏览代码

调整还原 动态同步加载初始资源

daxiongYang 7 年之前
父节点
当前提交
e9d808c9ae
共有 1 个文件被更改,包括 26 次插入8 次删除
  1. 26 8
      static/config/init.js

+ 26 - 8
static/config/init.js

@ -10,8 +10,7 @@
10 10
    js: [
11 11
      window.SITE_CONFIG.cdnUrl + '/static/js/manifest.js',
12 12
      window.SITE_CONFIG.cdnUrl + '/static/js/vendor.js',
13
      window.SITE_CONFIG.cdnUrl + '/static/js/app.js',
14
      // window.SITE_CONFIG.cdnUrl + '/static/plugins/mock-1.0.0-beta3/mock-min.js'
13
      window.SITE_CONFIG.cdnUrl + '/static/js/app.js'
15 14
    ]
16 15
  };
17 16
@ -21,30 +20,49 @@
21 20
    _icon.setAttribute('rel', 'shortcut icon');
22 21
    _icon.setAttribute('type', 'image/x-icon');
23 22
    _icon.setAttribute('href', resList.icon);
24
      document.getElementsByTagName('head')[0].appendChild(_icon);
23
    document.getElementsByTagName('head')[0].appendChild(_icon);
25 24
  })();
26 25
27 26
  // 样式
28 27
  (function () {
29
    var _script = null;
30
    for (var i = 0; i < resList.css.length; i++) {
28
    document.getElementsByTagName('html')[0].style.opacity = 0;
29
    var i = 0;
30
    var _style = null;
31
    var createStyles = function () {
32
      if (i >= resList.css.length) {
33
        document.getElementsByTagName('html')[0].style.opacity = 1;
34
        return;
35
      }
31 36
      _style = document.createElement('link');
32 37
      _style.href = resList.css[i];
33 38
      _style.setAttribute('rel', 'stylesheet');
39
      _style.onload = function () {
40
        i++;
41
        createStyles();
42
      }
34 43
      document.getElementsByTagName('head')[0].appendChild(_style);
35 44
    }
45
    createStyles();
36 46
  })();
37 47
38 48
  // 脚本
39 49
  document.onreadystatechange = function () {
40
    if (document.readyState === 'complete') {
50
    if (document.readyState === 'interactive') {
51
      var i = 0;
41 52
      var _script = null;
42
      for (var i = 0; i < resList.js.length; i++) {
53
      var createScripts = function () {
54
        if (i >= resList.js.length) {
55
          return;
56
        }
43 57
        _script = document.createElement('script');
44 58
        _script.src = resList.js[i];
45
        _script.async = false
59
        _script.onload = function () {
60
          i++;
61
          createScripts();
62
        }
46 63
        document.getElementsByTagName('body')[0].appendChild(_script);
47 64
      }
65
      createScripts();
48 66
    }
49 67
  };
50 68
})();