<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else
window.onload = downloadJSAtOnload;
</script>
Computer, Technology, Databases, Google, Internet, Mobile, Linux, Microsoft, Open Source, Security, Social Media, Web Development, Business, Finance
Wednesday, January 01, 2014
How to defer loading of javascript efficiently using the Google way?
If there is a piece of code that is intended to be loaded after a webpage finishes loading, one efficient method as recommended by Google is to use listeners. An article on feedthebot illustrates the Google's method. The following code should be placed in your HTML just before the </body> tag. Also, all code blocks supposed to be delayed are to be placed in an external js file (defer.js in this case).
Subscribe to:
Post Comments (Atom)
Popular Posts
-
新加坡人口400万,亚洲人口4亿,全世界人口6亿。 但是,我一人可能就很有可能是世界最傻的了。我真是个不折不扣的大木头。真是受不了自己。
-
If you live in the North-East and commute early, your daily transit routine just got a whole lot sweeter. The Land Transport Authority (LTA)...
-
Ever looked up from your phone, realized your bus was pulling away, and had to sprint like you were running the 2.4km NAPFA test? We are put...
-
It is indeed very sad news coming from Google - Google Reader is to be discontinued from 1 July 2013 onwards. This is Google's yet anot...
-
Google url shortener service, goo.gl , is now much improved with newly included features like easier copy and paste, and ability to delete e...
No comments:
Post a Comment
Do provide your constructive comment. I appreciate that.