Re: external javascript files

by "Karin Ransdell" <kransdell(at)squishedmosquito.com>

 Date:  Fri, 5 May 2000 12:48:46 -0500
 To:  <hwg-languages(at)hwg.org>,
"Jeff Adelsberger" <jade(at)edoc.com>
 References:  felix
  todo: View Thread, Original
----- Original Message -----
From: Jeff Adelsberger <jade(at)edoc.com>
To: <hwg-languages(at)hwg.org>
Sent: Friday, May 05, 2000 9:53 AM
Subject: external javascript files


> Hi all,
>
> I'm working on a project that requires the same javascript to be used
> across several pages, what are the pros and cons of using an external .js
> file to serve javascript?

This works well if
a) your script may be changing often
b) you want to slow down people who want to view and snag your source (like
I said, "slow down", because it isn't bulletproof)
c) your script is long and involved and you like your viewed source code
lean and mean (of course, this is moot if you just want people to be dazzled
by your reams of javascript source <g> ooooh ahhhhh)
d) your javascript is customized depending on user input (i.e. you're
pulling from a database)
e) you have reasonable assurance that your audience uses a browser that can
handled js to begin with

We have a particular client site (http://www.drkrocks.com/index1.htm) where
we've used javascript to build preambles and/or footers.

The actual content of the page might not change very often, but the
navigation menus and such might.  Rather than build complicated frames,
these changing elements are places in tables that are pulled into the page
with external js files that use document.writeln -

document.writeln("<table width=400 align=center><tr><td align=center>");
document.writeln('<!-- MENU FOOTER -->');
document.writeln('<a href=\"index1.htm\" target=\"_top\">Dr. K
Home</a>&nbsp;&nbsp;||&nbsp;&nbsp;');
document.writeln('<A HREF=\"bio.htm\">Bio</a>&nbsp;&nbsp;||&nbsp;&nbsp;');

and so on...

Since this particular function doesn't do any "tricks", just writes in text,
any increase in load time is negligible and makes updates and page additions
a breeze.

The downside of this particular technique, however, is that older
browsers -- or browsers with js turned off -- won't see these inclusions.
We're going with the statistics, however, and assuming that our
cutting-edge-rock-enthusiast-audience will have what it takes to view the
site. As they say, your mileage may vary ;)

For small or generic snippets of js that don't change, or for small sites,
however, cut-n-paste is your friend.

Karin
--------------------
K Ransdell
Escapade Development Team
www.squishedmosquito.com or www.escapade.org
kransdell(at)squishedmosquito.com

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA