Webmasters have long struggled with the puzzle of how to make effective use of JavaScript without sacrificing search engine optimization.

The reality is that many of today’s web sites with their animated rollover buttons, calculators, calendars, scrolling messages, and pop-up windows, contain a large amount of non-indexable text.

Few, if any of these pages, rank well in search engines. This is due to the fact that the JavaScript is placed in the <head> section of the document, pushing the actual text content far lower on the page than is optimal in respects to what the search engines are looking for "relevancy-wise".

However, there is a solution based on a seldom used technique that moves the majority of that JavaScript code completely off your pages and into a separate file. Doing this has two major benefits:

  1. It reduces the amount of code in your web pages which lends itself to better search engine ranking
  2. It allows you to re-use the code on other pages without duplicating it over and over again. By using common code on your pages you can then minimize your workload in the event you need to change the JavaScript in the future

For example, we recently built a web page for a client that did a full page of calculations showing potential cost savings for their service. The code used approximately 100 lines of JavaScript which would have ordinarily impacted the search engine ranking for that page. However, by placing the code in an external .js file we were able to substantially reduce the page size for the search engines. It also allows us to modify the JavaScript code in the future without changing the date of the web page. That’s an important advantage with search engines like AltaVista that score older pages higher in relevancy.

Any code that you would normally place in the <head> section of your web page can be placed into a separate .js file. This file should only contain your JavaScript code, without any other html codes. To call this external file, just reference it like this in the <head> section of your page:

<Script language-"JavaScript" src="financialimpact.js">
</Script>

When the page is loaded by the browser it will follow this link to get the JavaScript code. Of course, you can name the file anything you want as long as it ends with a .js extension.

Certainly you should experiment with this on your server to make sure it will work for you. Some servers may not recognize the .js file type and open a file download. To use this method successfully, your server must be set to map .js files to the MIME type application/x-javascript. If it doesn’t work, then your server probably isn’t setup for this application and you will have to contact the ISP or web hosing support and ask them to update the servers settings for this MIME type.

JavaScript can do some amazing things to help market your site. We prefer to use it only when we think it is going to serve a purpose such as a payback calculator or other customer focused feature. Used in moderation, JavaScript can help make the sale — which is always a very good thing!