This is quite a nice topic for discussion as it touches on various
important theoretical and practical issues.

"All my sites validate perfectly with <script> tags just before
closing
</body>.  What standard are you talking about? " - Mika

Yes its valid, and it is important to remember that validation is not
the goal at the end of the day. The goal is to have a website/
application that performs well and does whats meant to do.

So having your <script>s just before </body> its a good way to
decrease the loading time, and unobtrusive JS (like jQuery's) is a
great way to maintain your code separate for content (thereby reducing
possible future problems)

However, by not keeping your scripts and styles in one place (<head>)
could be headache when maintaining your application.

I agree with jake that this is an issue that has to be resolved by
each developer on a case by case basis. Personally I prefer to keep
essential scripts (like jquery.js) at the head, and then use some kind
of lazy loading (there are a couple of plugins for this) to import
additional scripts (and styles) as needs arise after the page has
finished loading. I would say its the best of both worlds, but again
it depends.


On Apr 8, 12:19 pm, "Jake McGraw" <[EMAIL PROTECTED]> wrote:
> From the comments on Yahoo Performance Rule # 
> 5http://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