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
-
Go to Yandex Webmaster.
-
Go to Indexing → JavaScript page renderingβ.
-
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 |
|
Boolean |
Possible values:
When the value is
See the detailed description of the states below. |
|
Boolean |
Possible values:
|
|
Boolean |
Possible values:
|
|
Boolean |
Possible values:
You can set the timeout in user settings if |
|
Boolean |
Possible values:
Use the parameter if your site implements a call to The Yandex bot perceives the call to How to detect content substitutionYou 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; } }