Know the three phases
Google processes a JavaScript page in three main phases: crawling, rendering and indexing. Googlebot queues a URL for crawling, then fetches it with an HTTP request and reads the response. If the response is a plain HTML page with all the content in it, that content is already in the HTML Google reads, although Google still queues the page for rendering. If the page is an app shell, the first response holds little more than a container and a script tag, so Google must render the page before it can see the content. Googlebot queues pages with a 200 status code for rendering, and the rendering queue can add a delay of a few seconds or longer. Once Google has the resources, a headless Chromium renders the page and runs the JavaScript. Google then indexes the rendered HTML and reads the links in it again. The practical result is that content which appears only after rendering can take longer to show up in Search.
Make sure links are real links
Google can only discover your links when they are anchor elements with an href attribute. Injecting links into the page with JavaScript is fine, as long as the injected links are real anchor elements with real addresses. Googlebot parses the response for href values and adds them to the crawl queue, and it parses the rendered HTML again after the scripts run. If you do not want Google to follow a link, use the nofollow mechanism on that link. Check the navigation on a rendered page.
Use the History API instead of fragments
Single-page apps often load different views when the URL fragment changes, for example a page at a hash address such as /#/products. Google cannot reliably resolve those addresses, so Google cannot reliably reach the views behind them. The fix is to give each view its own path, with ordinary href values, and use the History API to change the address when the view changes. Each link then points to a real address, the browser history still works, and Google can reach the view from the link. Open each view directly by its address to confirm that it loads without a click.
Set titles, descriptions and canonicals in the HTML first
Unique, descriptive title elements and meta descriptions help users pick the best result for their goal, so give every page its own. You can set or change both with JavaScript. Canonicals need more care. Google supports a rel="canonical" link injected with JavaScript, and it picks up the tag when it renders the page. The best place for the tag is the original HTML, though. If you inject the tag, make sure it is the only canonical on the page, and set it to the same value the original HTML would have given. Multiple or conflicting canonical tags can lead to results you did not expect.
Return the right status codes
Googlebot uses HTTP status codes to learn whether a page loaded, moved or disappeared. A page that cannot be found should return a 404, a page behind a login should return a 401, and a page that has moved should return a redirect status. Single-page apps often route pages on the client side, and meaningful status codes can be impossible or impractical there. Google calls these soft 404 errors. To avoid them, send the browser to a URL that the server answers with a 404 when the content does not exist, or add a noindex robots meta tag to error views with JavaScript. Both methods give Google a clear signal that the page should not be indexed.
Be careful with noindex and scripts
A robots meta tag with noindex tells Google not to index the page. When Google encounters a noindex tag, it may skip rendering and JavaScript execution. That means a script that removes noindex after the page loads may not work as you expect. If you want a page indexed, do not put noindex in the original page code. If a script needs to add noindex for an error view, add it only in the view that should stay out of the index, and test that view with URL Inspection.
Consider server-side rendering or pre-rendering
Google can render JavaScript, and the official guidance still says that server-side rendering or pre-rendering is a good idea. The reason is speed for users and reach for crawlers. Users see content sooner when the server sends finished HTML, and not every bot runs JavaScript. Content in the first response does not depend on rendering, although Google still queues the page for it. If full server-side rendering is too costly for your stack, a pre-rendering step for the important pages is a reasonable middle ground. Google also lists dynamic rendering as a workaround.
Check the rendered HTML, not the source
The HTML you see with View Source is the first response, and it may not hold the content Google indexes. The rendered HTML is what counts. Google suggests the Rich Results Test or the URL Inspection tool for this check, and both show the rendered HTML. Look for the headline, the main text, the links and the canonical tag in that rendered view. If the content is missing there, Google will not index it, however good the script is. Run the check on every template you ship, because one template can work while another fails.
Keep web component content visible
Google supports web components, and when it renders a page, it flattens the shadow DOM and the light DOM. Google can see only the content that is visible in the rendered HTML after that flattening. Google's example uses a slot so that both light DOM and shadow DOM content appear in the rendered HTML. Test a component on a rendered page before you rely on it for important text. Apply the same check to content in tabs and accordions.
Use lazy loading without hiding content
Lazy loading helps pages load quickly by fetching images only when they are about to appear. Google provides lazy-loading guidelines for doing this in a search-friendly way, and you should follow them. Test each lazy-loaded template in the rendered HTML, and confirm that the images and text you want indexed appear there.
Cache files with fingerprinted names
Googlebot caches aggressively to reduce network requests and resource use. The Web Rendering Service may ignore caching headers, which can leave it with old JavaScript or CSS files. Content fingerprinting avoids that problem. The fingerprint is a part of the file name, for example main.2bb85551.js, and it changes whenever the file content changes. Each update then gets a new file name, so the crawler fetches the new file. The web.dev guide on long-lived caching strategies covers the details.
Generate structured data carefully
Structured data can be generated with JavaScript and injected into the page as JSON-LD. Google accepts that approach. Test the final output on a live page to avoid issues. The structured data guide on this site covers the rules for each type.
A worked example with a made-up furniture shop
Imagine a furniture shop with a product catalogue built as a single-page app. Each chair has a view at a hash address, its title and description are set by a script after the data loads, and the category menu is made of buttons that do not hold links. The team checks the site and finds three problems. The rendered HTML of a product page shows no product name when the API is slow, and the category pages never appear as indexed pages because they have no real addresses. The team changes the menu to real anchor elements, moves each view to a path with the History API, and sends the title and description in the server response. They also return a 404 for products that no longer exist. URL Inspection then shows the product names and category links in the rendered HTML. This example is made up, and the steps show the method, not a result you should expect.
Know when this does not apply
A plain site with static pages does not need a JavaScript plan. If the HTML of each page holds the full content, the links are real anchor elements, and the titles and canonicals sit in the head, Google can read the content and links in that first response. Check the rendered HTML once to confirm that nothing changes, and then move on to other work. The effort in this guide matters when the page content depends on a script to appear at all.
Write down the checks for each template
Keep a short list for every template that a script builds. Confirm that the headline, main text, links and canonical appear in the rendered HTML. Confirm that each view has its own address and that the address returns the correct status code. Confirm that the title and description are unique. Confirm that any noindex tag sits only on the pages that should stay out of the index. Keep the list with the release notes, so a new template does not add a script-only page that nobody has checked. The indexing guide on this site explains the reports to watch once the checks pass.
Related help
Sources for technical rules
Google's documentation is the authority for its own search systems. This guide explains the work in our words.