Using External JavaScript Source Files

    October 31, 2006

By now most web designers and developers know that JavaScript causes a real headache for search engine spiders.

There are however a number of scripts which, whilst not absolutely essential to the functioning of a site, are nevertheless very handy.

So where do you draw the line between keeping your page as search engine friendly as possible and including reams of JavaScript to achieve the desired effects?

You may be surprised to learn that there is an alternative which keeps search engine spiders (reasonably) happy whilst drastically cutting down on the necessary scripts within any given web page.

External JavaScript Source Files

Let’s take the humble “Add Bookmark” script as an example (please note that I have replaced the < > brackets with [ ] brackets so as to be able to display the code properly within this article).

[script Language="JavaScript1.2" type="text/javascript"] var bookmarkurl = "";
var bookmarktitle = "Purple Doodads for sale";
function addbookmark()
if (document.all)
window.external.AddFavorite(bookmarkurl, bookmarktitle);

By placing the script’s function into an external folder and file (/java/bookmark.js for example) you will be able to streamline your code down to the following:

[script Language="JavaScript1.2" src="java/bookmark.js" type="text/javascript"][/script]

It’s worth remembering that this is probably one of the simplest examples of JavaScript out there and that the savings in terms of code are going to be substantial with larger scripts.

This method is also worth its weight in gold, so to speak, if you are running a number of scripts on the same page.

Just remember to create a different source file for each script, so as not to confuse matters unnecessarily.

Through the use of external JavaScript files you not only save yourself having to write (or even copy/paste) the same bulky scripts again and again, you are also saving search engine spiders from becoming seriously disillusioned with your web page and going elsewhere in search of easier prey.

Always remember that any web site should make a search engine’s life as easy as possible.

If you do use JavaScript in your pages, this approach will prevent unnecessary complications when having your site indexed, whilst at the same time easing your task of coding.


Add to | Digg | Reddit | Furl

Bookmark WebProNews:

An accomplished copywriter, Sasch Mayer has been writing content for web and print for well over a decade.
He is currently living in the Republic of Cyprus and working under contract to IceGiant Web Design.