Posted by Andy Dingley on 04/12/06 13:44
xyZed wrote:
> I want to use external javascript files. The only javascript I have is
> from affiliate links and many pages have different ads with different
> scripts. Is there anyway I can still use an external file?
Yes. You might not be able to put _all_ of your JS into it though.
Stick the complicated stuff into an external .js file,
write simple wrapper functions that pass page-specific parameters into
a common core function, and store these wrapper functions on the page.
This doesn't "strip all the JS out of the page", but it does remove
nearly all of the complex JS you might have to maintain later into one
central copy, and that's what really matters.
You can also re-write your JS to be less dependent on parameters and
more dependent on context when it's called. This is mainly a technique
for lists of thumbnail images and similar situations - rather than
hard-coding each call with a string constant for the image URL, have it
read the necessary information from the HTML element that raised the
event. (This can be tricky to do well cross-platform though).
[Back to original message]
|