How do I noindex ajax-loaded pages without a head tag?

by dejuan.watsica , in category: SEO , 8 months ago

How do I noindex ajax-loaded pages without a head tag?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by jose_gulgowski , 7 months ago

@dejuan.watsica 

To prevent search engines from indexing AJAX-loaded pages without a head tag, you can add a noindex directive in the X-Robots-Tag HTTP header. This header is sent with the AJAX response, and it allows you to control the indexing of the page.


Here's an example in JavaScript using jQuery:

1
2
3
4
5
6
7
8
9
$.ajax({
  url: "your-ajax-loaded-page.html",
  beforeSend: function(xhr){
    xhr.setRequestHeader("X-Robots-Tag", "noindex");
  },
  success: function(data) {
    // Your success handling code here
  }
});


Note that this will only work if the server is configured to pass on the X-Robots-Tag header in its responses. If the server is not configured to pass this header, you will need to modify its configuration or contact the server administrator for assistance.