I can't seem to find a clear answer on this. If my page looks like this:
<html>
<head>
<script>
var mypets = [
{ 'type': 'dog', 'name':'rover' },
{ 'type': 'cat', 'name':'kitty' }];
$('#btnShowEm').click(function() { $('#emptyAtFirst').text(mypets[0].name); });
</script>
</head>
<body>
<div id='emptyAtFirst'></div>
<button id='btnShowEm">ShowEm</button>
</body>
<html>
Will Google index the 'mypets' data even though it is not displayed in the html at the start? The real world page declares lots of content in a similar javascript object and displays bits of it in response to user actions; I want to know if I have to do something more in order to get the page to index based on all the content, not just what is visible in html before the javascript stuff runs.
Will Google index and rank JavaScript content added to a page? Yes. We placed text using JavaScript on product category pages to increase relevance. And, we even replaced the entire body of a web page with JavaScript generated content and found those pages via Google search querying for terms within the new content.
Once Google's resources allow, a headless Chromium renders the page and executes the JavaScript. Googlebot parses the rendered HTML for links again and queues the URLs it finds for crawling.
Inline JavaScript can be achieved by using Script tag inside the body of the HTML, and instead of specifying the source(src=”…”) of the JavaScript file in the Script tag, we have to write all the JavaScript code inside the Script tag.
I do not recommend that you rely on content stored in JavaScript to drive your SEO efforts.
Google has said "If fancy features such as JavaScript, cookies, session IDs, frames, DHTML, or Flash keep you from seeing all of your site in a text browser, then search engine spiders may have trouble crawling your site." That's why Google recommends using Lynx to preview your site to see how their spider sees it.
Although it is almost certain that Google does read all your JS, I doubt they give you as much (if any) rank juice from JavaScript code. It is better to place your important content in your HTML. Perhaps HTML5 data-attributes are more favorable to search engines. If this is the case, to maximize the likelihood that the search engine will read it, you will probably want to have all this content in the HTML when the initial page loads, rather than populating it via JavaScript after page load.
Further reading here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With