Sunday, 15 June 2014

asynchronous - JavaScript code improvement -


I'm just not a big javascript performance guru, am I thinking now, can I compact the following code now? It is not written in the form of packing or compression, but in the way it is written.

  (function () {var jq = document.createElement ('script'); var a = 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'; a.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 (a); document.documentElement.firstChild.appendChild (ga);}) ();  

Cheers people!

as it is written, and performance is unrelated, but it is more compact, Writing correctly:

  function append script (url, async) {var el = document.create element ('script'), root = document.documentElement; El.async = async; El.src = url; // Insert an IE6 bug (http://bugs.jquery.com/ticket/2709) Avoid using root.insertBefore (L, root.firstChild); } Ependascript ('http://example.com/js/jquery.1.3.2.js', Incorrect); Ependascript ('http://example.com/js/jquery.alphanumeric.js', incorrect); Ependascript ('http://example.com/js/common.js', Incorrect); Ependascript (('https:' == document.location.protocol? '// SSL:' 'www') + '. Google-analytics.com / ga.js'), true);  

No comments:

Post a Comment