NYCPHP Meetup

NYPHP.org

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

Michael B Allen ioplex at gmail.com
Wed Feb 6 16:12:33 EST 2008


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/



More information about the talk mailing list