Is it possible to disable Google indexing of some web page if this is placed to head tag

<meta name="googlebot" content="noindex" />

using only JS? Or is it all a hoax and only the finished page is taken into account when indexing?

  • I doubt it. This would assume that Googlebot (a) parses the Javascript as you would like it to and (b) actions it. As, AFAIK this is not standard it would not work. Why not just use robots.txt instead?
    – davidgo
    Commented Jan 29, 2022 at 1:10
  • What about Single Page Application ? Google wrote that it already knows how to analyze JS in page. Commented Jan 29, 2022 at 8:59

2 Answers 2


Google supports inserting meta tags with JavaScript, including noindex. You can have JavaScript insert <meta name="googlebot" content="noindex" /> into the <head> of the page and Google will stop indexing the page once it renders it.

Google recommends inserting noindex with JavaScript in its documentation: Understand JavaScript SEO Basics | Google Search Central  |  Google Developers

Avoid soft 404 errors in single-page apps

In client-side rendered single-page apps, routing is often implemented as client-side routing. In this case, using meaningful HTTP status codes can be impossible or impractical. To avoid soft 404 errors when using client-side rendering and routing, use one of the following strategies:

  • Use a JavaScript redirect to a URL for which the server responds with a 404 HTTP status code (for example /not-found).
  • Add a <meta name="robots" content="noindex"> to error pages using JavaScript.


Here is sample code for the noindex tag approach:

.then(response => response.json())
.then(product => {
  if(product.exists) {
    showProductDetails(product); // shows the product information on the page
  } else {
    // this product does not exist, so this is an error page.
    // Note: This example assumes there is no other meta robots tag present in the HTML.
    const metaRobots = document.createElement('meta');
    metaRobots.name = 'robots';
    metaRobots.content = 'noindex';

The usual caveats about JavaScript rendering and SEO apply: It often takes Google extra time (weeks or even a couple months) to decide that it needs to render the page, render it, and react to the results. In other words inserting noindex with JavaScript is not likely to be as fast as inserting it into the HTML code on the back end.


I believe the answer from Stephen here does not hold true anymore.

From the very same link, it now says: If Google encounters the noindex tag, it skips rendering and JavaScript execution. Because Google skips your JavaScript in this case, there is no chance to remove the tag from the page. Using JavaScript to change or remove the robots meta tag might not work as expected. Google skips rendering and JavaScript execution if the robots meta tag initially contains noindex. If there is a possibility that you do want the page indexed, don't use a noindex tag in the original page code.

What I gather from this is that it's fine to use JS to inform of noindex, but no way of reversing this with JS - one must use HTML.

  • What about SPA ? Where we have only one tag on a page, and ewresing else it's just of JS Commented Apr 25 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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