SpriteMe
Speaking Engagements
JSConf.eu
Berlin, Nov 7-8, slides
Fronteers
Amsterdam, Nov 5-6, slides
Øredev
Malmö, Nov 4, slides
Amazon Tech Talk
Seattle, Oct 30, slides
SpeedGeeks LA
Los Angeles, Oct 26, slides pptx, zip
The Ajax Experience
Boston, Sept 14-16, Browserscope, EFWS
jQuery Conference
Boston, Sept 12-13, slides
OSCON
SJ, July 22, 11:35am, slides
Velocity
SJ, June 22-24, slides, slides
WordCamp
SF, May 30, slides
Google I/O
SF, May 27-28, slides
Microsoft Tech·Ed
LA, May 12 2:45pm, slides
Web 2.0 Expo
SF, April 2, slides
O'Reilly Master Class
SF, March 30
SXSW
Austin, March 14, slides
High Performance Web Sites blog 

Browser script loading roundup

How are browsers doing when it comes to parallel script loading?

Back in the days of IE7 and Firefox 2.0, no browser loaded scripts in parallel with other resources. Instead, these older browsers would block all subsequent resource requests until the script was received, parsed, and executed. Here’s how the HTTP requests look when this blocking occurs in older browsers:

The test page that generated this waterfall chart has six HTTP requests:

  1. the HTML document
  2. the 1st script – 2 seconds to download, 2 seconds to execute
  3. the 2nd script – 2 seconds to download, 2 seconds to execute
  4. an image – 1 second to download
  5. a stylesheet- 1 second to download
  6. an iframe – 1 second to download

The figure above shows how the scripts block each other and block the image, stylesheet, and iframe, as well. The image, stylesheet, and iframe download in parallel with each other, but not until the scripts are finished downloading sequentially.

The likely reason scripts were downloaded sequentially in older browsers was to preserve execution order. This is critical when code in the 2nd script depends on symbols defined in the 1st script. Preserving execution order avoids undefined symbol errors. But the missed opportunity is obvious – while the browser is downloading the first script and guaranteeing to execute it first, it could be downloading the other four resources in parallel.

Thankfully, newer browsers now load scripts in parallel!

This is a big win for today’s web apps that often contain 100K+ of JavaScript split across multiple files. Loading the same test page in IE8, Firefox 3.6, Chrome 4, and Safari 4 produces an HTTP waterfall chart like this:

Things look a lot better, but not as good as they should be. In this case, IE8 loads the two scripts and stylesheet in parallel, but the image and iframe are blocked. All of the newer browsers have similar limitations with regard to the extent to which they load scripts in parallel with other types of resources. This table from Browserscope shows where we are and the progress made to get to this point. The recently added “Compare” button added to Browserscope made it easy to generate this historical view.

While downloading scripts, IE8 still blocks on images and iframes. Chrome 4, Firefox 3.6, and Safari 4 block on iframes. Opera 10.10 blocks on all resource types. I’m confident parallel script loading will continue to improve based on the great progress made in the last batch of browsers. Let’s keep our eyes on the next browsers to see if things improve even more.

recent posts:

Page Speed 1.6 Beta – new rules, native library

Zen and the Art of Web Performance

jQuery 1.4 performance

News