Loading scripts asynchronously.
Was checking ways to asynchronously load javascript files in the page.
Came across these two excellent blogs - http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/
http://friendlybit.com/js/lazy-loading-asyncronous-javascript/
Came across these two excellent blogs - http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/
http://friendlybit.com/js/lazy-loading-asyncronous-javascript/
There are six main techniques for downloading scripts without blocking:
- XHR Eval – Download the script via XHR and
eval()
the responseText. - XHR Injection – Download the script via XHR and inject it into the page by creating a script element and setting its
text
property to the responseText. - Script in Iframe – Wrap your script in an HTML page and download it as an iframe.
- Script DOM Element – Create a script element and set its
src
property to the script’s URL. - Script Defer – Add the script tag’s
defer
attribute. This used to only work in IE, but is now in Firefox 3.1. document.write
Script Tag – Write theHTML into the page using
document.write
. This only loads script without blocking in IE.