Indexing pages with JavaScript β

With Yandex Webmaster, you can manage the indexing of site pages where content is displayed via JavaScript. You can specify whether the indexing bot should execute JavaScript on pages when crawling your site. This can be useful if SSR (Server-Side Rendering) or pre-rendering is not implemented on the site.

Note

Executing JavaScript code may create additional load on your server.

Indexing management

  1. Go to Yandex Webmaster.

  2. Go to Indexing → JavaScript page renderingβ.

  3. Choose one of the options. By default, At the bot’s discretion is enabled. This means the bot will independently determine whether to execute JavaScript code on the site’s pages. To make a decision, it may, for example, assess the quality and completeness of the content on the pages with and without JavaScript and load the one that is likely to be more useful to the visitor.

    Tip

    Prohibit rendering if SSR (Server-Side Rendering) or pre-rendering is implemented on the site.

Advanced rendering settings

If content on your site loads with a delay, you can inform Yandex about it using a special JavaScript code.

On website pages where content loads with a delay, create the window.YandexRotorSetting object in such a way that it is processed before the DomContentLoaded event. Within this object, you can specify parameters that the Yandex bot will respond to when processing the page. The parameters are listed in the table below.

Code example:

<script>
    window.YandexRotorSettings = {
        WaiterEnabled: true;
        FailOnTimeout: false;
        NoJsRedirectsToMain:true
    }
</script>

Parameter

Type

Description

WaiterEnabled

Boolean

Possible values:

  • true;
  • false.

When the value is true, it is possible to check the states:

  • IsLoaded;
  • IsError.

See the detailed description of the states below.

IsLoaded

Boolean

Possible values:

  • true — if the DomContentLoaded event is executed, the content is considered loaded, and the page content is indexed by the Yandex bot.
  • false.
  • Arbitrary function. Examples

IsError

Boolean

Possible values:

  • true — content loading is considered erroneous, and the page content is not processed by the Yandex bot;
  • false.

FailOnTimeout

Boolean

Possible values:

  • true — after the timeout expires, the bot will not index the page;
  • false — the bot will index the part of the content that it manages to load before the timeout expires.

You can set the timeout in user settings if WaiterEnabled: true.

NoJsRedirectsToMain

Boolean

Possible values:

  • true — the Yandex bot will ignore the redirect to the home page of the site;
  • false.

Use the parameter if your site implements a call to window.history.back(), for example, when using the History API.

The Yandex bot perceives the call to window.history.back() as a transition to the home page without changing the content. As a result, content from other pages may appear on the home page.

How to detect content substitution

You may notice that in search results, the description of the home page changes to the description of internal pages, or the rel="canonical" attribute changes to the attribute of internal pages.

Examples of JavaScript code implementation

Wait for the element with the desired CSS selector to load
<!-- We're waiting for an '.observable-class' element.
It will be created in 10 seconds --->

<!-- This code should be inserted directly into your html --->
<script>
    window.YandexRotorSettings ={
        WaiterEnabled: true
    }
</script>

<!-- This code can be loaded via <script src="...">-->
<script>
    var intervalId = setInterval(function(){
        if (document.querySelectorAll('.observable-class').length > 0){
            window.YandexRotorSettings.IsLoaded = true;
            clearInterval(intervalId);
        }
    }, 1000);
</script>

<!-- An example script. Create an element with the class we need -->
<script>
    setTimeout(function(){
        var div = document.createElement('div');
        div.classList.add('observable-class');
        div.innerText = "These are the droids you're looking for.";
        document.body.appendChild(div);
    }, 10000);
</script>
Wait 5 seconds after loading
<!-- We recommend relying on waiting for specific elements.
The indexing bot may load resources for an indefinitely long time --->

<!-- This code should be inserted directly into your html --->
<script>
    window.YandexRotorSettings ={
        WaiterEnabled: true
    }
</script>

<!-- This code can be loaded via <script src="...">-->
<script>
    setTimeout(function(){
        window.YandexRotorSettings.IsLoaded = true;
    }, 5000);
</script>

Examples of function implementation within isLoaded

Check the status of the page
<!--In this example, we check if there are more than 10 div elements on the page-->

window.YandexRotorSettings ={
            WaiterEnabled: true,
            IsLoaded: function(){
                return document.body.querySelectorAll('div').length > 10;
            }
        };
Wait for content to load in the title element
window.YandexRotorSettings = {
    WaiterEnabled: true,
    IsLoaded: function() {
        return document.title.length > 0;
    }
}

Learn more

Contact support

If the pages don't appear in search results for a long time or were excluded, or if you have other questions about indexing of subdomains of the site, fill out the form below:




You can also go to