2

I host maps. Each map has its own unique URL. But all these URLs return the exact same small HTML/CSS code, just to show something to the user while the assets and content are being loaded via Ajax.

Once loaded, the title and the content is updated.

However it seems Google isn't bothering with this:

I know Google crawlers run JavaScript, but not in this case? What are the possible reasons for this? And the possible solutions?

I have tested with the Search Console explorer. The page is rendered exactly as it should.

  • 1
    Have you tried the "fetch as Google" feature in Google Search Console? It has a "fetch and render" mode that can alert you to problems. – Stephen Ostermiller Mar 10 '18 at 16:07
  • 1
    Indeed, I have tried it. It doesn't give any error and the result is as expected. – leyou Mar 10 '18 at 20:46
2

Google can crawl javascript, but it's not guaranteed that it will be able to read all types of javascript.

The meta tags of a page are loaded in the html, and Google reads this. There is no certainty that Google will change the meta tags based on your javascript.

The following code was reported to work in changing a site's meta tags while having Googlebot properly read it to update the SERP tags. I have personally not tested it.

<script>
  var m = document.createElement('meta'); 
  m.name = 'description'; 
  m.content = 'This tutorial has some helpful information for you, if you want to track how many hits come from browsers where JavaScript has been disabled.'; 
  document.head.appendChild(m);
</script>

Another one:

document.title = "Google will run this JS and show the title in the search results!";

It is better if you can update the tags in PHP, but if you have to do it in JS you can try these out. If you do and they work, please do let me know as I might like to use this script later on as well.

  • 1
    I'm not doing the first thing (adding new meta elements) but I'm doing the second one (updating the document's title). And of course updating the body. I'm thinking it's probably because there's too much to load/it takes too long (about 2 seconds). So far that's the only explanation I have. – leyou Mar 10 '18 at 21:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.