Optimizing a JavaScript Site for Search Engines - Move the Code
(Page 6 of 9 )
Now, let’s move the JavaScript to an external file. Open a text editor, like Notepad; cut and paste the section of code right after the <!-- symbols and right before the //--> symbols into your editor. Save your file, making sure to name it something like date.js, using the drop down box in your text editor to save as all files, not *.txt.

Figure-5: Save As *.js
Now, you need to point the browser to the off-loaded script by referring to it in your HTML file like in the next example.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Website</title>
<script src="date.js" language="javascript" type="text/javascript"></script>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis ligula lorem, consequat eget, tristique nec, auctor quis, purus. Vivamus ut sem.</p>
</body>
</html>
Example-2: JavaScript Date Function off-loaded
So by using an external JavaScript file, you now have 10 lines of code instead of over 50 lines, with exactly the same end result. By off-loading your JavaScript, you get the same date function in the corner of the webpage, like in Figure-1, as well as eliminating over 40 lines of code in your HTML that the search engine spider would just disregard anyways. Plus, you’ve moved your important content farther up in your page where it receives more weight of relevancy by a search engine during a search query, as well as giving your keywords better density, and your page an overall better text to code ratio.

Figure-6: New Ratio with off-loaded JavaScript
Next: Navigation and Effects >>
More Search Optimization Articles
More By Jennifer Sullivan Cassidy