This guide will help you determine and fix the problems with JavaScript, which can block your page or certain contents on the pages working with JavaScript from display in searching for Google. Despite the fact that Google Search can process JavaScript, there are some differences and restrictions that it is important to consider when developing your pages and applications to take into account how Google robots gain access and display your content. Our guide on the basics of JavaScript SEO offers more information on how to optimize your site with JavaScript for Google Search.
Googlebot is designed to be a bona fide network user. The main task is to scan, while Googlebot should avoid worsening user experience on the site. Googlebot and its WEB RENDERING SERVICE (WRS) component are constantly analyzing and identify resources that do not affect the main content of the page and may not be loaded. For example, reporting and errors that are not important for the main content are not subject to loading. Use a report on scanning statistics in Search Console to monitor the activity of Googlebot and WRS on your Google website.
If you suspect that JavaScript problems can block your page or specific contents on the pages with JavaScript from display in searching for Google, follow these steps. If you are not sure that it is JavaScript that is the main reason, follow our general debugging manual to determine a specific problem.
window.addEventListener('error', function(e) {
var errorText = [e.message, 'URL: ' + e.filename, 'Line: ' + e.lineno + ', Column: ' + e.colno, 'Stack: ' + (e.error && e.error.stack || '(no stack trace)')].join('
');
var DOM_ID = 'rendering-debug-pre';
if (!document.getElementById(DOM_ID)) {
var log = document.createElement('pre');
log.id = DOM_ID;
log.style.whiteSpace = 'pre-wrap';
log.textContent = errorText;
if (!document.body) document.body = document.createElement('body');
document.body.insertBefore(log, document.body.firstChild);
} else {
document.getElementById(DOM_ID).textContent += '
' + errorText;
}
});
Particular attention should be paid to preventing errors like "Soft 404", especially if your site uses a single -page application (SPA). In order for errors to be not indexed by search engines, use the following strategies:
fetch(`https://api.example.com/page/${id}`).then(res => res.json()).then((page) => {
if (!page.exists) {
window.location.href = '/not-found';
}
});
fetch(`https://api.example.com/page/${id}`).then(res => res.json()).then((page) => {
if (!page.exists) {
const metaRobots = document.createElement('meta');
metaRobots.name = 'robots';
metaRobots.content = 'noindex';
document.head.appendChild(metaRobots);
}
});
If your SPA application uses a client JavaScript to process errors, often a problem arises when erroneous pages meet the status of 200 instead of the desired error code.
Googlebot will not be able to provide permission to access functions such as using a camera or other user resolutions. If your page requires the provision of such permits to access the content, provide the user with an alternative way to view without the need to provide permits.
The previously used approach with URL fragments (for example, https://example.com/#/products) is no longer supported for scanning Googlebot, since since 2015 the Ajax-Crawling scheme has been stopped. Instead of URL fragments, it is recommended to use History API for dynamic content loading in SPA.
To avoid caching problems, use the content print. This will avoid the use of outdated JavaScript or CSS resources, and Googlebot will always receive relevant files. An example is the use of content version files in the title of files as Main.2BB85551.js. Details on the strategy of long -term caching read on Web.dev.
Use the Rich Results Test tool or the URL testing tool to check that your web components are correctly rendered. It is important to remember that WRS may not support some mechanisms for working with DOM, for example, a mechanism
After you correct the indicated problems, test the page using the Rich Results Test or the URL testing tool in the Google Search Console again. If the problem is solved, you will see a green checkmark, and errors will not be displayed. If errors remain, seek help from the Search Central community.
For additional questions and consultations, you can contact the Seo.computer SEO company by mail info@seo.computer or through WhatsApp: +79202044461.
ID 115