Can googlebot do basic javascript? [duplicate]
Asked Answered
S

3

1

Suppose I have something like this page:

<noscript>You need JS for this page</noscript>
<script>
    document.write('you have javascript');
    $(function() { /* Some DOM heavy coding */ });
<script>

What will this look like to google? If someone searches google for "you have javascript" will they see my page?

Spore answered 2/4, 2012 at 17:20 Comment(0)
H
4

The safest answer is: don't rely on it. In particular because you're doing heavy DOM coding.

If the code must be in Google for search purposes then create that part of the HTML on the server and use JavaScript only for interaction. Google's web crawlers are getting smarter but I don't expect them to understand arbitrary JavaScript code.

Hong answered 2/4, 2012 at 17:27 Comment(0)
D
4

Yes, Google’s Bots Understand Code
How much javascript does Googlebot read
Google Admits GoogleBot can Parse and Execute JavaScript Code on-the-fly

You may find this useful as well: View a Web Page as 'Googlebot'

And for completeness: Google 'googlebot javascript' and these are all on the first page.

Doubleness answered 2/4, 2012 at 17:23 Comment(2)
It is clear that Google is working towards being able to index javascript-generated content and that they are doing some of that now. Unless you have a more specific reference than the one you cited, it is not clear exactly what javascript generated content Google does and doesn't index. So, I'd say it's overstepping a bit to just answer this question with a "Yes". It's more like a "Maybe". If you want it to be indexed, it should be in the markup, not in the javascript. If you want it to be indexed by all search engines it has to be in the markup.Handball
Better answer now? Also, the "Yes" was the title of the page linked toDoubleness
H
4

The safest answer is: don't rely on it. In particular because you're doing heavy DOM coding.

If the code must be in Google for search purposes then create that part of the HTML on the server and use JavaScript only for interaction. Google's web crawlers are getting smarter but I don't expect them to understand arbitrary JavaScript code.

Hong answered 2/4, 2012 at 17:27 Comment(0)
N
1

On my own side, I can confirm GoogleBot executes JavaScript, and according to the IP, it was really it, and not just UA spoofing from a browser.

I learned it today, when I wanted to generate some statistics on the use of AdBlockPlus and the likes, when I saw GoogleBot appearing in the logs, which I was not expecting. Seems he also use JavaScript execution to figure some new URLs to crawl; I mean, if a JavaScript loads a page in an IFRAME with some parameters in the URL, it may first try to load the page without the parameters, then only later try to load the page with the parameters. This may suggest it first execute the JavaScript in a kind of sandbox to see what it do.

Nita answered 1/8, 2013 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.