[thelist] JavaScript - linking v. embedding

John.Brooking at sappi.com John.Brooking at sappi.com
Fri Jun 11 13:20:25 CDT 2004


> Date: Thu, 10 Jun 2004 13:36:16 -0400
> From: Norman Bunn <norman.bunn at craftedsolutions.com>
> Subject: Re: [thelist] JavaScript - linking v. embedding
> 
> My general rule of thumb is to use linked when used on more than one page 
> and embedded when used once.  The reason is that browsers can cache the 
> linked file, thus saving load time and improving execution speed.
> 
> Norman

Agreed. An even better reason to link, IMHO, is that if you discover a bug
in the code, and it's used all over the place, you only have to fix it once.
It's just another form of reusable code.

Another personal best-practice I would recommend in .js files is to make
everything into a function, not immediate code (except setting some global
variables if necessary). That way, you just load the .js file anywhere in
the <head> section, and call the function(s) where needed. I think this is
cleaner than having to remember where to include the file because it will
cause something to happen right away. Plus of course it allows you to use it
more than once on the same page.

John Brooking, Application Developer
Sappi Fine Paper
-- 
 

This message may contain information which is private, privileged or
confidential and is intended solely for the use of the individual or entity
named in the message. If you are not the intended recipient of this message,
please notify the sender thereof and destroy / delete the message. Neither
the sender nor Sappi Limited (including its subsidiaries and associated
companies) shall incur any liability resulting directly or indirectly from
accessing any of the attached files which may contain a virus or the like. 


More information about the thelist mailing list