T-XU.COM      
Home |
  Home>Computer Programming>Javascript>
Using External JavaScript Files
By Amrit Hallan        [Hits: 29553]



When you have lots of JavaScript functions and you plan to usethem on many web pages, it is always advisable to keep them in aseparate file, and then include that file on every page wherethose functions are required. This way, you can better organizethem, you don't have to copy/paste the code again and again(imagine if it runs to 100 or more lines!!), and you'll beforced to write more generalized code for better integration andscalability.

Besides, enclosing the common JavaScript routines in externalfiles keeps your web pages uncluttered and search engine spidersand crawlers are able to reach the important content easily.They don't have to shuffle through tens of lines of scripts.

In the first edition [that appeared in my newsletter -BYTESWORTH REACHOUT] of my article I had omitted the process ofcreating the external JavaScript files, but when one of myreaders asked me how to do it, I had to re-write the article.

It's very simple. Use any text editor of your liking (if youhand-code your HTML, you can use the same editor that you usefor your HTML editing). Write the required code, and save thefile with .js (dot js) extension.

I'm going to give you a small example.

Suppose your JavaScript file is "myjfuncs.js".

and it has a function to return the bigger number of the twosupplied as parameters (you can simply start with the function,no need to write

So when we use one of its functions in a JavaScript:



In this way, we can use all the complex functions contained inthe myjfuncs.js file.
  Top Articles
*Simplified form to mail: Unlim
*Capturing Video And Audio Stre
*Building HTML codes automatica
*How to handle web surfers, who
*Instant plug-in scripts that h
*Anti right-click pop up : pop
*Validating Numerical Input wit
*New Customizable JavaScript Me
*Ask Mr. D - JavaScript
*Inexpensive Area Rugs Give You
*Spice Up Your Web Site with Ja
*Evaluation of Keywords for an
  Related Articles
*Validating Form Input in JavaS
*Guide to creating simple chrom
*Some Useful JavaScript Tricks
*Dirty Web Promotion Tricks #1
*Grow Your Subscribers Exponent
*Spice Up Your Web Site with Ja
*Ask Mr. D - JavaScript
*Make your website scream with
*Javascript; Browser Detection
*Javascript Basics 01
*Instant plug-in scripts that h
*Validating Numerical Input wit


Prev: Validating Form Input in JavaScript   Next: Guide to creating simple chromeless popup windows.



Home | Site Map | Bookmark this site | T-XU RSS
Copyright 2007 T-XU.com - All Rights Reserved Worldwide.