≡ Menu

SEO Optimization and JavaScript


This article deals with whether the JavaScript Codes disrupts SEO Optimization of your site or not.

You might find a lot of articles related to using JavaScript Code or not for better SEO Optimization. Some might advise not to use it at all, while some advise to use it within certain restrictions. For example, “don’t use long JavaScript codes”, “use them at the bottom of your page” etc.

Advertisement: If you are serious about earning money online this one video will change your life. This guy is a millionaire from Australia who was a broke a couple of years ago. You Must Watch This Video Now!!! Free to Watch. (Will open in new tab.)

First of all make it very clear – do not fear putting the JavaScript codes if they are really required. In no way it’s going to disrupt you in SEO Optimization. The point is WHERE to keep the codes.

Learn about one way link building

This has been a topic of debate since a long time now as far as SEO optimization is concerned. Do the codes really mater? Does the placement of codes really matter?

Lets discuss where we usually keep the JavaScript codes. Most of the webmasters prefer inserting the JavaScript codes at the beginning of the HTML file, between the <HEAD> and </HEAD> section of the file.

It goes like this:

<html>
<head>
<title>The site’s title</title>
<meta name=”description” content=”The site’s description.”>
<meta name=”keywords” content=”The important keywords”>
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
function f1()
{
// The codes
}
function f2()
{
// The codes
}
// End –>
</SCRIPT>
</head>
<body>
<p>The Body of the Page!</p>
</body>
</html>

Irrespective of the length of the code it’s always preferred there. The question is WHY? Is it really required to be kept there as a software rule, or the codes can be kept anywhere in the file?

The JavaScript codes can be kept ANYWHERE in the file. They will work as fine. So why do the webmasters prefer keeping it there? It’s probably to maintain the clarity of the page. Moreover if the page gets too long and the codes are scattered throughout, it becomes difficult to find out the exact JavaScript code that has to be debugged or that has to be changed. This is a kind of convention too that is being followed by most of the webmasters. So the placement of the JavaScript codes is just a customary practice rather than a rule and it has nothing to do with SEO optimization.

The search engines have a mammoth task of spidering millions of ever growing web pages. Google has already reached the 3 billion mark. They are really busy and do not want to be loaded with any more work.

Imagine a web page that has just 2 lines of text or information but 120 lines of JavaScript Code. For getting those 2 lines of information the search engines have to pass through all the unnecessary 120 lines of code. Keeping in mind what is written above do you think the search engines will like the page? They are very busy and if for 2 lines of information they have to work so hard then it’s unlikely that this page will ever get a good ranking. How much ever hard you try to optimize it.

Many SEO gurus have come out with an idea to tackle this problem to optimize such a page. According to them putting the JavaScript code at the bottom of the page will solve all the problems since the search engines will not have to go farther down to search the 2 lines of information.

This is what they say:

<html>
<head>
<title>The site’s title</title>
<meta name=”description” content=”The site’s description.”>
<meta name=”keywords” content=”The important keywords”>
</head>
<body>
<p>The Body of the Page!</p>
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
function f1()
{
// The codes
}
function f2()
{
// The codes
}
// End –>
</SCRIPT>
</body>
</html>

Note that in this situation the body of the page is above the JavaScript Code. According to the SEO gurus the search engines will now get the content of the page before the code and therefore the importance of the page increases. Right? WRONG!

What if there were 2 more lines of content right at the bottom of the page just after the </SCRIPT> tag? The search engines will have to come to the bottom of the page to get those 2 lines of information. Even if you do not have any information at the bottom of the page the search engines do spider the whole page. They don’t have any idea whatsoever whether you have included some content at the bottom of your page or not. The search engines look for </HTML> tag or end of page whichever comes earlier to end their crawling. So they crawl your whole page anyway irrespective of where you have inserted the JavaScript code and will obviously rank your page on the basis of the content found. This again brings us to square one. Where should you include the JavaScript code if at all?

Those who know this scripting language know very well that a different file can be created to keep all the JavaScript codes separately. This file has an extension of .js. It is a simple file that can be created using notepad. It has nothing except the JavaScript code. NO HTML tags are included. You can place functions, code and style sheets into this external Js file and refer to the file with one line from each web page that wants to use the functions contained in it.

This .js file is kept in the same directory where the file in respect of whom the codes were written resides. Whenever the required codes are called they are taken from the .js file and executed. This file is called only once and then taken from the cache memory of your computer for further execution. It is retrieved only when the cache memory is expired.

This is how an external JavaScript file is included in the page:

<html>
<head>
<title>The site’s title</title>
<meta name=”description” content=”The site’s description.”>
<meta name=”keywords” content=”The important keywords”>
<SCRIPT LANGUAGE=”JavaScript” SRC=”externalfile.js”>
</SCRIPT>
</head>
<body>
<p>The Body of the Page!</p>
</body>
</html>

This process has a few advantages. External JavaScript files saves bandwidth, which can be achieved by caching any JavaScripts and Cascading Style Sheets (CSS) that are repeated often in a web site. Secondly the length of the page reduces giving way to faster download.

You can always instruct a search engine to index a page or not using a robots.txt file. Once the .js file is ready and uploaded to the server you can always tell the search engines NOT to index your external JavaScript file allowing them to save their time. If you don’t know how to write robots.txt file, read article on creating robots.txt file.

This technique solves both the purposes – the search engines do not have to look for the information, they get it without wasting a second and your purpose is solved too – you give search engines the important information fast!

However you need not bother if your page is full of Unique and Valuable information, or if you are providing Quality services. The JavaScript code is a trivial matter if your site is content rich. Secondly, the search engines actually do not spider the JavaScript codes. As soon as they find the <SCRIPT> tag they stop spidering. They resume their job again once they get the </SCRIPT> tag. But they have to go through the codes. So, by including the JavaScript code you are only taking a little bit of their time. Yes, too much of JavaScript code with very less content may irritate them. This is the only reason why a page with a lot of code with comparatively less content does not get a good Google PR (page rank). Unfortunately it’s the JavaScript code that has to take all the blame.

Truly speaking there is an unnecessary confusion being created with the use of JavaScript code vis-à-vis SEO optimization. Give some useful content and great service, your JavaScript codes will then play virtually no role in SEO optimization.

A Very Important Note: Google Site Search isn’t able to index content contained in JavaScript. To make sure it does, is to ensure that all of the text that needs to be indexed is visible in a text-based browser. That is in a lay man’s language – JavaScript is meant for scripting only, if you add text in JavaScript thinking you would get top ranks in organic results you will not get that.


{ 15 comments… add one }
  • papa Destra April 24, 2010, 10:50 pm

    Thank’s for your tips

  • World Wide Web Seo. w3seo May 5, 2010, 3:38 pm

    “SEO Optimization and JavaScript” This tip is really really for my seo (w3seo.com). Thank much!!!!

  • Bonkers May 6, 2010, 5:22 am

    Search engine can execute javascript.
    If search engine can not read javascript then how do you explain this
    http://rathamahata.blogspot.com/2007/01/how-do-search-engines-bots-handle.html

  • Thanks for the article. It clears all my doubts for Javascripts in SEO. I have read alot of posts but, they all provided incomplete information.

  • Vikram July 8, 2010, 9:49 am

    Very helpful tips.
    Thanks

  • Dilip Shaw July 20, 2010, 7:15 am

    @Bonkers I never said that search engines cannot execute JavaScript codes, however its better to let JavaScript do what it does best – scripting.

    Its always better and advisable to use good and unique content in your pages and use JavaScript only for what its meant to be.

    Hope that helps.

  • Doug December 20, 2010, 2:54 am

    Wow, how ridiculous. You refer to javascript “codes” and tell us the search engines are too busy to index pages with javascript? That’s totally ignorant. Google knows all about javascript and just ignores it…DUH. Have you ever looked at the javascript a Google map injects into the page BODY? Or any widget, for that matter? You really are a fool.

  • Lam SEO December 29, 2010, 12:11 am

    Good post on SEO for Javascript. 🙂

    What a/b the drap n drop function like BBC News. Could you please explain the tips there? Tks.

  • Goa January 12, 2011, 8:58 am

    javascript is something which search engine robots do not read and may treat it as suspicious thing or something they do not know and hence long javascripts might not be a good option

  • Dilip Shaw January 18, 2011, 5:23 am

    @Doug Try optimizing a page with *only* JavaScript codes and No content. All the best!!!

  • Suresh February 21, 2012, 6:09 am

    Nice article. Information provided in a very simple and nice way. Thanks guys!

  • Brian K Alfaro April 26, 2012, 7:56 am

    I come here for just answering a Question for my friend by searching a query in Google “java script role in SEO” .But i can’t explain how much informative and well written content with simply written powered with examples in post.Great work and gives a sound knowledge in solving my Query.

  • Goswami Yashpal February 13, 2014, 8:51 am

    Hello guys,

    My Question is suppose my website contains to many Java Script files, so does it affect in my page rank?

  • Dilip Shaw February 18, 2014, 6:27 am

    Goswami, No Java Script files does not affect your website’s page rank. However please be informed that the page rank that you see in the tool bar does not reflect the correct and latest PR of your website.

    Google hides this information to make sure people do not get the real PR and try getting links from high PR websites to gain PR for their own websites.

    This is right in a way because webmasters will then start abusing PR and the whole system of ranking correctly may fail.

    Engineers at Google thought its better therefore to hide the real page rank from the public, to make the whole system of ranking fair to all.

  • Flight Factory December 1, 2016, 2:56 am

    We have just started with SEO for our travel site (flight search). Thank you for these, will be implementing this for sure 🙂

Leave a Comment

Get Adobe Flash player