Drawbacks of Implementing Canonical tag using javascript

Please Recommend This Story For

Perhaps you may know well that Canonical Tags are used to mention the exact location of contents that look some like this..


<!DOCTYPE html>
<html>
    <head>
        <link href="http://www.example.com/" rel="canonical" />
        <title>Canonical</title>
        <script type="text/javascript">
            window.onload = function () {
                var canonical = "";
                var links = document.getElementsByTagName("link");
                for (var i = 0; i < links.length; i ++) {
                    if (links[i].getAttribute("rel") === "canonical") {
                        canonical = links[i].getAttribute("href")
                    }
                }
                alert(canonical);
            };
        </script>
    </head>
    <body>
        <h1>Canonical</h1>
    </body>
</html>
 In 2009 Google began to support the link rel="canonical" tag and later on Bing and Yahoo also.  Now Google might execute the javascript, but javascript generated code for canonical tags is virtually guaranteed that it will ignored by Google in future.
Always keep it in your mind that the use of the canonical tag is to specify the true location of content. Javascript injection is a significant enough security problem across the Internet that Google is *incredibly* unlikely to trust a Javascript generated canonical tag.  Bottom line, it's got to be in the actual generated HTML of the page. So you can now judge the idea of using it as there are problems associated with javascript. Also having a # at the end of URLs. Google hasn't said anything about using javascript for canonical tag. Google only exactly crawlled the links if they are in correct shape, JavaScript links are on less stable ground and are required to pass muster with Google's JavaScript parser. As Google Bots do not do th e the javascript and might be possible they would not see the canonical tags by implementing the javascript according to the basic law web working 101.If it is non html then it is unsure that later on in future the search engines everywhere will see it. Even google has only recently started executing javascript.

0 comments

Copyright 2008 Seo GrinePK | Converted by Search Engine Optimization | |