
The best way to load external JavaScript - sant0sk1
http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/
======
mrshoe
Wouldn't it be yet another optimization to just include that loadScript
function in the HTML? Reducing round trips to the server is a common technique
in web site optimization.

I realize that script will be cached after the first time, but it's so small
that it will hardly affect the performance of subsequent requests anyway.

------
michaelfairley
Google conveniently hosts and distributes most of the common Javascript
libraries through their CDN, and allows external developers to load them using
this technique. <http://code.google.com/apis/ajaxlibs/>

~~~
sant0sk1
Has anybody else noticed slower load times using Google's hosted libraries
than their own?

~~~
mrshoe
It's probably faster to serve them off your own server due to HTTP keepalive.

Sure, making a new connection to google's CDN might be faster than making a
new connection to your server, but it's definitely not going to be faster than
sending a little more data over an existing connection. Not to mention the
extra DNS lookup.

~~~
blasdel
The idea is that if _everyone_ uses the google-hosted jquery, it'll almost
always be in the browser cache.

------
psadauskas
I've found the best way is just just `cat` all my js files together, and just
include that one...

~~~
michaelfairley
The article points out that that strategy will cause your page to block while
it's loading. See [http://www.stevesouders.com/blog/2009/04/27/loading-
scripts-...](http://www.stevesouders.com/blog/2009/04/27/loading-scripts-
without-blocking/) for more info.

~~~
psadauskas
Not if you put it at the bottom. Yes, it does block the page, but hopefully
your page will degrade gracefuly until the js is loaded. If it doesn't, then
you want it at the top, where it will block. It will load slower, sure, but
people won't have to see a broken site.

