The Advantages of Using External JavaScript

Programming for Search Engines 101. An area for avid PHP and .NET developers to chat about Programming techniques and how to make better use of search engines.

Moderator: Moderators

The Advantages of Using External JavaScript

Postby silvester » Mon Apr 19, 2010 6:03 am

Can you imagine how fast search engine spiders could crawl and index your site if they had less code to wade through? Search engine spiders are looking for your page content, titles, alt tags, etc. They are not looking for those awesome graphics you designed.

They are also not concerned about your CSS or JavaScript, so make it easier on them and easier on your site visitors when your pages load faster by including your CSS and JavaScript in an external file.

The concept of External JavaScript is the same as External CSS. You simply link your .js files between the HEAD tags of your web pages and you only have one file to edit. This makes maintenance to your site a breeze!

For example, let's imagine that I have a file named ads.js which contains JavaScript code that rotates banner ads on all 500 pages of my site. If I link this file (as shown below) between the HEAD tags of all of my web pages, and each month I need to change these banner ads, I only have to change the banner ad references in one file. If I had the entire JavaScript code in each of my web pages, I would have to edit each of those 500 pages every month. Yikes! What a maintenance nightmare. The same concept is true with External CSS.

<script language="JavaScript" src="scripts/ads.js"></script>

If you have many .js files, put them their own directory (ie. "scripts", "js", etc.) to keep your web page elements organized as you should also do with your images.

To make this an absolute path, include your entire domain, ie. src="http://www.yoursite.com/scripts/ads.js"

Reference Article: ""
silvester
 
Posts: 89
Joined: Mon Nov 10, 2008 12:59 am

Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests