|
|
 |
Externalize JavaScript
If your pages contain complex JavaScript, you can simplify your pages by putting the JavaScript in external files. The resulting pages will be simpler for search engines to read. Complex JavaScript code can be misinterpreted by some search engine spiders and indexed as content, diluting the more important text on the page.
Here are two examples of the same page, with and without internal JavaScript:
<html>
<head>
<title>Jellyfish Classification</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore()
{ //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&
(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=
MM_preloadImages. arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</head>
<body>
<h1>Jellyfish Classification<h1>
<p>Jellyfish (also called jellies or sea jellies as they are not true fish) are animals that belong to Phylum Cnidaria, included in the class Scyphozoa.</p>
</body>
</html>
|
<html>
<head>
<title>Jellyfish Classification</title>
<script language="JavaScript" src="external.js" type="text/javascript"></script>
</head>
<body>
<h1>Jellyfish Classification<h1>
<p>Jellyfish (also called jellies or sea jellies as they are not true fish) are animals that belong to Phylum Cnidaria, included in the class Scyphozoa.</p>
</body>
</html>
|
If you must include JavaScript in your pages, consider moving the JavaScript to the bottom of the pages, so the spiders can crawl your content first. If you have to include JavaScript in the head section, make sure the JavaScript appears at the end of the head, after important information such as the TITLE tag.
An additional benefit of externalizing JavaScript is that it saves bandwidth when the JavaScript is used on several pages, because the browser does not have to download the JavaScript again for each additional page. It also makes it easier to update the JavaScript when it is in a single file.
|