I find putting the script files at the end to be invaluable from a
performance standpoint.  This also ties in with making the site degrade
gracefully for those who still have javascript disabled.

The site looks and works fine with no javascript at all.  Once the page has
been rendered, the script files are downloaded and activated to improve the
user experience.

Because I've stayed away from having the javascript redraw elements on first
load, there are no unnatural jumps or flickers when the javascript does
load.

I've done some testing on a 56k modem with putting the scripts in the head,
and there is a significant performance hit on the page being available to
the user.

Personally I've become a convert and not try to put all scripts at the
bottom whenever possible.

JK

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Jake McGraw
Sent: Tuesday, April 08, 2008 9:20 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: $(window).bind("load",function(){ vs onready


>From the comments on Yahoo Performance Rule # 5
http://developer.yahoo.net/blog/archives/2007/07/high_performanc_5.html:

:: snip ::

There are some cases where you wouldn't want your JS at the bottom.
For example, if you were using an "ondomready" event that many of the
js libraries supply, you would want the code to execute towards the
top. If you were to move all your JS to the bottom of the page, the
event would be rendered useless.

However, it's nice to know that having it at the top is a performance
hit so that I can weigh the positives with the negatives before moving
forward.

:: snip ::

So there is an instance where, using jQuery $(document).ready() or any
JavaScript library DOM ready functionality, it makes more sense to
keep your script tags in the document head.

In the end, it's up to the developer which method to use, as both can
be utilized successfully. I said in my original post that this is
mostly the territory of debate for "standardistas", therefore its
worth inside of real-world web application development is
questionable. Considerations of end user experience often override
whatever the W3C or ECMA specificies. I'm just providing an alternate
opinion so developers can make an informed consideration. Thankfully,
jquery-en provides a professional environment where we can have this
discussion.

- jake

On Tue, Apr 8, 2008 at 11:40 AM, Mika Tuupola <[EMAIL PROTECTED]>
wrote:
>
>
>  On Apr 8, 2008, at 6:23 PM, Jake McGraw wrote:
>
>
> > Regardless of whether it validates, it's considered best practices to
> > keep all <script> tags out of the body:
> >
>
>  It all depends who "consideres".
>
>  http://developer.yahoo.com/performance/rules.html#js_bottom
>
>
>
> > If you put your scripts at the very end of a page, it is possible that
> > a user already sees part of the page including a button with a
> > JavaScript function call, while the rest of the page hasn't loaded
> > yet. Result: user pushes button and gets JavaScript Error Message
> > Alerts, because the browser can't find the script (yet).
> >
>
>
>  True, if you do things like:
>
>  <input type="button" onclick="checkform()"  />
>
>  Then again not a problem if you write unobtrusive JavaScript.
>
>  $(function() {
>     $("input").bind("click", checkform);
>  });
>
>  And isn't jQuery about writing unobtrusive JavaScript? ;)
>
>
>
>  --
>  Mika Tuupola
>  http://www.appelsiini.net/
>
>

Reply via email to