Continued from page 1
Both of these problems can be solved simply by using external files. You create one external file for your CSS and another file for your JavaScript. These could be named mysite.css for
CSS and mysite.js for
JavaScript. These files can be created in any plain text editor or html code editor, they are nothing more than files that contain most of
CSS or JavaScript code from
web pages.
With JavaScript you have an opening JavaScript tag, then a comment tag, then assorted functions and what not, followed by a closing comment tag and a closing JavaScript tag. Your external file would start with
opening comment tag, contain all
functions and such, and end with
closing comment tag. You would leave both
opening and closing JavaScript tags in
html page. If you have more than one JavaScript on
page you can move all
code into one external js file. Simply copy it into
file in
same order as it exists in
JavaScript tags on
html page. You will only need
one pair of opening and closing comment tags.
Once your JavaScript is moved off
page you will need to tell
web page where to find it. This is done in
JavaScript tag that was left on
page in
head section. Right now this will be an opening JavaScript tag placed right up against
closing JavaScript tag, with no additional code in between. You will place
reference to
external JavaScript code inside
opening JavaScript tag like this:
script language="JavaScript" type="text/JavaScript" src="mysite.js"
Placing CSS styles in an external file is handled in exactly
same manner. Move
styles into
external file, and then refer to that external file with your style tag in
head section of
web page like this:
link href="mysite.css" rel="nofollow" rel="stylesheet" type="text/css"
An added benefit of moving
code into external files is that you can then change
styles of your whole site simply by changing
code in
one external file.
Once you have moved
code into external files you will have greatly simplified
code on each page. This will take you a long way towards making your pages lean and mean, and very search engine friendly.
You can find sample external files for this article on my web site at: www.howtogurus.com/free-articles.html
Copyright 2005 - George Peirson

George Peirson is a successful Entrepreneur, Internet Trainer and author of over 30 multimedia based tutorial training titles. Read more articles by George Peirson at www.howtogurus.com/free-articles.html