How do I prevent ajax-generated content from being indexed by search engines?


by zion , in category: SEO , a year ago

How do I prevent ajax-generated content from being indexed by search engines?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

3 answers

by jacey.lubowitz , a year ago


To prevent AJAX-generated content from being indexed by search engines, you can add the following tag in the HTML head:

<meta name="robots" content="noindex">

This will instruct search engines not to index the content generated by the AJAX request. You can also use the X-Robots-Tag HTTP header to achieve the same result for content delivered via the AJAX response:

X-Robots-Tag: noindex

It's worth noting that some search engines may still index the AJAX-generated content, despite these tags and headers, so it's recommended to not rely on them to entirely prevent content from being indexed.

by larry_orn , 3 months ago


Additionally, you can use the "Disallow" directive in your robots.txt file to prevent search engine crawlers from accessing specific AJAX-generated URLs. Here's an example:

1 2

User-agent: * Disallow: /path/to/ajax-generated-content

Replace "/path/to/ajax-generated-content" with the actual URL or directory path where your AJAX-generated content is located.

It's important to note that not all search engines may honor the "Disallow" directive, so this method may not be fully effective in preventing indexing of AJAX-generated content.


by dorothea , 2 months ago


Another approach is to load the AJAX-generated content using JavaScript and dynamically insert it into the DOM. By doing this, search engine crawlers that do not execute JavaScript will not be able to see or index the AJAX-generated content.

Here's an example of how you can accomplish this:

  1. Wrap the AJAX-generated content in a container element with a unique ID, such as a
<div id="ajax-content"></div>

  1. In your JavaScript code, use AJAX to fetch the content and insert it into the container element:
var xhr = new XMLHttpRequest();'GET', 'ajax-url', true);
xhr.onreadystatechange = function() {
    if (xhr.readyState === 4 && xhr.status === 200) {
        document.getElementById('ajax-content').innerHTML = xhr.responseText;

This method ensures that the content is only loaded when JavaScript is executed, effectively preventing search engines from indexing it.

However, keep in mind that some search engines now execute JavaScript to index content, so this method may not be entirely foolproof. By combining multiple techniques, such as using the noindex meta tag and the Disallow directive, you can increase the likelihood of preventing AJAX-generated content from being indexed by search engines.