NYCPHP Meetup

NYPHP.org

[nycphp-talk] JavaScript just above form in body?

Peter Sawczynec ps at sun-code.com
Wed Feb 6 21:04:08 EST 2008


JavaScript(s) loads in an order similar to how CSS loads. Without
getting to deep, I have found incidences where a JavaScript snippet or
code section will perform as expected when the actual JS code is
embedded with script tags in the head of the HTML page, but when this
same script is loaded as a JS source file it will fail. Peter

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of Michael B Allen
Sent: Wednesday, February 06, 2008 4:13 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] JavaScript just above form in body?

On 2/6/08, John Campbell <jcampbell1 at gmail.com> wrote:
> On Feb 6, 2008 2:06 PM, Michael B Allen <ioplex at gmail.com> wrote:
> > Is it considered bad practice to emit scripts within the body of a
> > page such as immediately preceeding the form that uses it? It seems
to
> > work fine but from looking at some random sites I have yet to see an
> > example of this. Logically it makes sense to put the JavaScript
close
> > to where it will be used no?
>
> The standards nazis will tell you to put scripts in the head.  The
> performance freaks will tell you to put your scripts as the last
> element in the body.  Putting javascript in the middle of the page, is
> bad practice but can simplify development.  So where you put scripts
> is up to you... I prefer putting all scripts as the last element in
> the body because performance is more important to me than standards
> compliance, but I'm not afraid to put them in the middle or inline to
> get things done faster.

<snip>
> I highly recommend using a js library with a good onLoad event
> replacement (my favorite is jQuery).  The standard default onload
> event sucks because it waits for all images to be downloaded rather
> than being a "DOMContentReady" event.

Hi John,

Actually I'm trying not to use much JavaScript if I can help it. I
just need a few functions to help with forms (so far).

How about src-ing a .js? I've been looking at random pages and I'm
surprised to see that not many pages actually do this. Is there a
reason?

Mike

-- 
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php




More information about the talk mailing list