【发布时间】:2009-12-02 02:18:56
【问题描述】:
我不是一个伟大的 JavaScript 性能专家。只是想知道,我可以让下面的代码更紧凑吗?不像打包或压缩它,而是它的编写方式。
(function() {
var jq = document.createElement('script');
var an = document.createElement('script');
var cm = document.createElement('script');
var ga = document.createElement('script');
var domain = 'http://example.com/';
jq.src = domain + 'jquery.1.3.2.js';
an.src = domain + 'jquery.alphanumeric.js';
cm.src = domain + 'common.js';
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(jq);
document.documentElement.firstChild.appendChild(cm);
document.documentElement.firstChild.appendChild(an);
document.documentElement.firstChild.appendChild(ga);
})();
干杯!
【问题讨论】:
标签: javascript asynchronous performance