JavaScript SEO Basics
Many modern sites use JavaScript to build pages in the browser. Google can process JavaScript, but it adds steps and potential pitfalls. If your content only appears after scripts run, it is worth checking that search engines can see it.
How Google handles JavaScript
Google crawls a page, then queues it for rendering with a recent version of Chrome, which runs the scripts. Content that appears after rendering can be indexed, but rendering can happen later than the first crawl, and other search engines and tools may be less capable. Simple, server-delivered HTML is generally the most reliable.
Common problems
- Content loaded only after a click or scroll. Google does not click buttons or type into forms. Content that needs a user action may not be seen.
- Links that are not real links. A
<div>with a click handler is not a link. Search engines follow<a href="...">. See internal linking for SEO. - Blocked scripts or resources. If
robots.txtblocks files needed to render the page, Google may see an incomplete version. See robots.txt explained. - Slow or failing scripts. If your page needs a lot of JavaScript before content appears, it harms users and indexing.
- Titles and descriptions set by script only, which may be missed or delayed.
- Fragment URLs. Addresses using only
#to change content are not treated as separate pages.
Better approaches
- Serve important content in the initial HTML. Server-side rendering, static generation, or pre-rendering all do this. Many small sites are simpler and faster as plain static pages. See static hosting and Jamstack explained.
- Use real links and real URLs for each page, with the History API if you build a single-page app.
- Put key tags in the HTML: title, meta description, canonical, and robots directives. See title tags and meta descriptions.
- Keep JavaScript lean. See how to reduce JavaScript on your website.
- Return proper status codes for missing pages. See 404 errors and soft 404s.
How to test
- URL Inspection in Search Console: view the rendered HTML and a screenshot of what Google sees.
- View source vs. inspect: view the raw source to see what the server sends. If your text is missing there, it depends on scripts.
- Disable JavaScript in your browser and see what remains.
Do not forget users
Some visitors use slow devices or have scripts blocked. A page that works without heavy scripts is more resilient and accessible.
Should you worry?
If your site is a simple static or CMS-based site, probably not. If you use a framework that builds everything in the browser, check carefully.
For another thing that depends on how your server responds, read 404 errors and soft 404s: what they mean for SEO.