// 04.Dec.2009

Loading Scripts Without Blocking

Fortunately, there are ways to get scripts to download without blocking any other resources in the page, even in older browsers. Unfortunately, it’s up to the web developer to do the heavy lifting.

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 the <script src=""> HTML into the page using document.write. This only loads script without blocking in IE.

Last Revision: December 4th, 2009 at 09:47

Comments are closed.