Authored by 毕凯

优化 JS 记载

... ... @@ -116,10 +116,63 @@
{{/wechatShare}}
<script>var STATIC_RESOURCE_HASH = '{{startTime}}';</script>
{{#if devEnv}}
<script>var STATIC_RESOURCE_PATH = '//{{devHost}}:{{port}}';</script>
<script>
var STATIC_RESOURCE_PATH = '//{{devHost}}:{{port}}';
window.jsFiles = ["//{{devHost}}:{{port}}/libs.js?t={{startTime}}", "//{{devHost}}:{{port}}/{{module}}.{{page}}.js?t={{startTime}}"];
</script>
<script src="//{{devHost}}:{{port}}/libs.js?t={{startTime}}"></script>
<script src="//{{devHost}}:{{port}}/{{module}}.{{page}}.js?t={{startTime}}"></script>
<script>
(function() {
window.jsFiles.forEach(function(file) {
var preloadLink = document.createElement('link');
preloadLink.href = file;
preloadLink.rel = 'preload';
preloadLink.as = 'script';
document.head.appendChild(preloadLink);
});
window.loadJS = function loadJS(src, retryMode) {
var ref = window.document.getElementsByTagName('script')[ 0 ];
var script = window.document.createElement('script');
var scriptSrc;
if (retryMode) {
scriptSrc = src;
} else {
src && window.jsFiles.push(src);
scriptSrc = window.jsFiles.shift();
}
if (!scriptSrc) {
return;
}
script.src = scriptSrc;
script.crossorigin = 'anonymous';
if (!retryMode) {
script.onerror = function() {
if (script.parentNode) {
script.parentNode.removeChild(script);
}
loadJS(script.src, true);
};
}
script.onload = function() {
loadJS();
};
ref.parentNode.insertBefore(script, ref.nextSibling);
return script;
};
loadJS();
}());
</script>
{{!-- <script src="//{{devHost}}:{{port}}/libs.js?t={{startTime}}"></script>
<script src="//{{devHost}}:{{port}}/{{module}}.{{page}}.js?t={{startTime}}"></script> --}}
{{^}}
<script>var STATIC_RESOURCE_PATH = '//cdn.yoho.cn/yohobuywap-node/{{version}}';</script>
<script src="//cdn.yoho.cn/yohobuywap-node/{{version}}/libs.js?t={{startTime}}" crossorigin="anonymous"></script>
... ...