読み物Technical SEO · Performance

Level: Intermediate

JavaScript SEO, Website Performance, and Core Web Vitals

How search engines render JavaScript, which rendering strategy to choose, and how to measure and improve LCP, INP, and CLS with field and lab data.

Edeeson Opina10 min read

An Intermediate lesson card: lesson 10 of the SEO series, JavaScript SEO, Website Performance, and Core Web Vitals, with the Miso fox excited.

What you’ll learn

  • Describe how Google crawls, renders, and indexes JavaScript pages
  • Choose between client-side, server-side, and static rendering
  • Compare the HTML source with the rendered DOM
  • Measure and improve LCP, INP, and CLS using field and lab data
On this page
  1. How Google processes JavaScript pages
  2. Client-side, server-side, and static rendering
  3. Rendering and discoverability: rules that matter
  4. JavaScript-generated content and the HTML versus the rendered DOM
  5. Lazy loading
  6. Core Web Vitals
  7. Field data versus lab data
  8. Mobile usability
  9. Practical optimization methods
  10. Improving LCP
  11. Improving INP
  12. Improving CLS
  13. Performance testing workflow
  14. Common mistakes and troubleshooting
  15. Key takeaways
  16. Exercise
  17. References
  18. What's next

Modern websites are often applications: a framework builds the page in the browser, fetches data after load, and updates the screen without full page loads. That's great for interactivity, but it changes what a crawler sees and when it sees it. It also changes how fast the page feels. This lesson covers how search engines handle JavaScript, which rendering strategies are safest for search, and how to measure and improve the Core Web Vitals.

How Google processes JavaScript pages

Google handles JavaScript pages in three phases:

  1. Crawling: Googlebot fetches the URL and reads the initial HTML response.
  2. Rendering: the page is queued for rendering in an evergreen (regularly updated) version of Chromium, which runs the JavaScript and builds the final page.
  3. Indexing: Google indexes the rendered HTML and extracts links from it for further crawling.

Rendering usually happens quickly, but it's an extra step that can be delayed and can fail: scripts may error, time out, be blocked by robots.txt, or depend on things Googlebot doesn't do, like clicking, scrolling, or granting permissions. Other search engines and many social-media link previewers render JavaScript less, or not at all. The more of your important content and links are present in the initial HTML, the less you depend on rendering going right.

Client-side, server-side, and static rendering

Client-side rendering (CSR): the server sends a minimal HTML shell and a JavaScript bundle; the browser builds the content.

HTML
<!-- What a crawler receives from a pure CSR app before rendering -->
<body>
  <div id="root"></div>
  <script src="/assets/app.4f2c1.js"></script>
</body>

Everything depends on rendering. Titles, canonicals, content, and links appear only after the script runs.

Server-side rendering (SSR): the server runs the application for each request and sends complete HTML, which JavaScript then makes interactive ("hydration"). Crawlers see the content immediately.

Static site generation (SSG): pages are rendered to HTML at build time and served as files. Fast and very crawlable; content updates need a rebuild, or incremental regeneration where the framework supports it.

Most modern frameworks (Next.js, Nuxt, SvelteKit, Astro, Remix and others) support SSR and SSG, and often let you choose per route. For pages that should rank, prefer SSR or SSG. Reserve pure CSR for areas that don't need search traffic, such as dashboards behind a login.

Google once suggested dynamic rendering (serving pre-rendered HTML to bots and the app to users) as a workaround. It now describes it as a workaround rather than a recommended solution; SSR, static rendering, or hydration are the long-term approaches.

Rendering and discoverability: rules that matter

  • Links must be <a href> elements with resolvable URLs. Router calls attached to buttons or <div>s aren't links to a crawler.
  • Use real URLs, not fragments, for different pages. https://www.example.com/#/products is one URL to Google; use the History API with paths like /products/.
  • Each route needs its own title, description, and canonical, rendered on the server if possible.
  • Return real status codes. A CSR app often returns 200 for every URL and shows "Not found" with JavaScript, creating soft 404s. Return 404 from the server, or add <meta name="robots" content="noindex"> on error views.
  • Don't block resources needed for rendering in robots.txt.
  • Don't rely on user interaction to load primary content. Content behind tabs that's already in the DOM is fine; content fetched only after a click isn't seen.

Here's how a Next.js App Router page can provide its metadata on the server, so it's in the initial HTML:

app/guides/[slug]/page.tsxTSX
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { getGuide } from "@/lib/guides";

export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
  const guide = await getGuide((await params).slug);
  if (!guide) return {};
  return {
    title: guide.title,
    description: guide.summary,
    alternates: { canonical: `https://www.example.com/guides/${guide.slug}/` },
  };
}

export default async function GuidePage({ params }: { params: Promise<{ slug: string }> }) {
  const guide = await getGuide((await params).slug);
  if (!guide) notFound(); // sends a real 404 status
  return (
    <article>
      <h1>{guide.title}</h1>
      <div dangerouslySetInnerHTML={{ __html: guide.html }} />
    </article>
  );
}

dangerouslySetInnerHTML is used here only because the guide's HTML is assumed to come from a trusted, sanitized source; never pass user input to it.

JavaScript-generated content and the HTML versus the rendered DOM

The HTML source is what the server sent. The rendered DOM is the page after scripts ran. They can differ a lot, and search engines index the rendered result. When debugging, compare both:

  • View page source in the browser shows the original HTML.
  • Developer tools → Elements shows the current DOM.
  • In Search Console, URL Inspection → View crawled page (or Test live URL → View tested page) shows the HTML Google rendered, a screenshot, and resource loading problems and console messages.

Watch for conflicts: a server-rendered canonical or noindex that JavaScript later changes. Google may act on either version, so keep them consistent. In particular, if the initial HTML has noindex, Google may skip rendering, so JavaScript can't reliably remove it.

Lazy loading

Lazy loading defers offscreen images and content until needed. For images and iframes, the browser's native attribute is the simplest and is understood by crawlers:

HTML
<img src="/images/grinder-burrs.jpg" alt="Close-up of conical steel burrs" width="1200" height="800" loading="lazy">

Rules:

  • Don't lazy-load the main image above the fold, usually the Largest Contentful Paint element. Load it eagerly, and consider fetchpriority="high".
  • For content loaded by your own JavaScript, load it when it enters the viewport using IntersectionObserver, not on scroll events alone. Googlebot doesn't scroll, but it renders with a tall viewport, so viewport-based loading generally works.
  • Infinite scroll needs paginated URLs with real links behind it (lesson 8).

Core Web Vitals

Core Web Vitals are three metrics Google uses to measure real-user experience of loading, responsiveness, and visual stability. Each is assessed at the 75th percentile of page loads, separately for mobile and desktop:

  • Largest Contentful Paint (LCP): how long until the largest image or text block in the viewport renders. Good: 2.5 seconds or less.
  • Interaction to Next Paint (INP): how quickly the page responds visually to clicks, taps, and key presses, across the whole visit. Good: 200 milliseconds or less. INP replaced First Input Delay (FID) as a Core Web Vital in March 2024.
  • Cumulative Layout Shift (CLS): how much visible content moves unexpectedly. Good: 0.1 or less.

Google uses Core Web Vitals in its ranking systems as part of page experience, but it's explicit that great page experience doesn't override relevance: a fast page that doesn't answer the query won't outrank a slower one that does. Treat them as quality work that helps users first.

Field data versus lab data

  • Field data comes from real Chrome users (the Chrome UX Report, CrUX), aggregated over 28 days. It's what Search Console's Core Web Vitals report and the top of PageSpeed Insights show. Low-traffic pages may not have any.
  • Lab data comes from a simulated load (Lighthouse) on one device profile. It's reproducible and great for debugging, but it doesn't measure INP directly (Total Blocking Time is a lab proxy).

Fix what field data says is slow; use lab data to find why.

Mobile usability

Google indexes the mobile version of pages (mobile-first indexing). Make sure the mobile page has the same main content, headings, structured data, and metadata as desktop, with a responsive viewport:

HTML
<meta name="viewport" content="width=device-width, initial-scale=1">

Text should be readable without zooming, and tap targets large enough and far enough apart. Test on real phones and with the device toolbar in browser developer tools.

Practical optimization methods

Improving LCP

  • Serve HTML fast: caching, a CDN, and efficient server rendering reduce Time to First Byte.
  • Make the LCP image discoverable in the initial HTML (not set by JavaScript or only in CSS), load it eagerly with fetchpriority="high", and serve modern formats at sensible sizes with srcset.
  • Reduce render-blocking CSS and JavaScript; inline critical CSS where it helps.
  • Use font-display: swap or optional for web fonts so text can render early.

Improving INP

  • Break up long JavaScript tasks so the main thread can respond. Yielding (for example with await scheduler.yield() where supported, or setTimeout) between chunks of work helps.
  • Do less work in event handlers; show visual feedback first, then do heavy work.
  • Ship less JavaScript: remove unused code, split bundles by route, and defer non-critical third-party scripts.
  • Avoid large, frequent DOM updates and layout thrashing.
JavaScript
// Respond first, then do the heavy work in a later task
button.addEventListener("click", () => {
  button.setAttribute("aria-busy", "true");
  setTimeout(() => {
    applyFilters(); // expensive
    button.removeAttribute("aria-busy");
  }, 0);
});

Improving CLS

  • Always set width and height (or aspect-ratio in CSS) on images, videos, and iframes.
  • Reserve space for ads, embeds, and banners before they load.
  • Don't insert content above existing content unless it's a response to a user action.
  • Load web fonts carefully; size-adjusted fallbacks reduce shifts when fonts swap.

Performance testing workflow

  1. In Search Console, open Core Web Vitals to find URL groups marked "Poor" or "Needs improvement" in field data.
  2. Run a representative URL through PageSpeed Insights (opens in a new tab) to see its field data and Lighthouse diagnostics.
  3. Reproduce in Chrome DevTools: the Performance panel shows LCP and layout shifts, and live metrics for your own interactions.
  4. Fix one cause at a time, deploy, and confirm in the lab.
  5. Wait for field data to update over the next 28 days, and use Search Console's Validate fix.

Practice with RankMiso. Two parts of RankMiso (our free extension) fit this exercise. Compare HTML checks the title, canonical, robots, H1, structured data, and link counts in the rendered page against separately fetched HTML (Chrome) or an HTML file you choose, and marks each one as the same, added after rendering, removed after rendering, or changed. Its Performance section shows LCP and CLS as your browser observed them, plus an INP estimate: readings from your own visit to compare with the field data. Free on the Chrome Web Store (opens in a new tab) and Firefox Add-ons (opens in a new tab).

Common mistakes and troubleshooting

  • Content visible in the browser but missing in URL Inspection's rendered HTML. Check for blocked resources, script errors in the inspection details, or content that loads only after interaction.
  • Every URL returns 200. Configure your framework to send real 404s.
  • Lazy-loading the hero image. This often makes LCP much worse.
  • Optimizing for a Lighthouse score. A 100 in the lab with poor field data helps no one.
  • Different content on mobile. Mobile-first indexing means hidden or missing mobile content may not be indexed.

Key takeaways

  • Google renders JavaScript, but rendering adds delay and risk; important content, links, and metadata belong in the initial HTML.
  • Prefer server-side or static rendering for pages that need search traffic, with real links, real URLs, and real status codes.
  • Core Web Vitals (LCP ≤ 2.5 s, INP ≤ 200 ms, CLS ≤ 0.1 at the 75th percentile) measure real-user experience; relevance still comes first.
  • Use field data to find problems and lab tools to diagnose them.

Exercise

Pick one important page on a JavaScript-heavy site:

  • Compare View page source with Search Console's rendered HTML for that URL. List any content, links, or tags that exist only after rendering.
  • Run PageSpeed Insights and record field and lab values for LCP, INP (or TBT), and CLS.
  • Identify the LCP element and check whether it's lazy-loaded, discoverable in the HTML, and correctly sized.
  • Propose the two changes with the biggest expected effect, and how you'd verify each one.

References

What's next

That completes the Intermediate level: you can diagnose and fix the most common technical problems. The Pro level starts with the most direct evidence of how search engines treat your site: Advanced Crawling, Server Logs, and Crawl Optimization.

See every lesson in SEO: From Fundamentals to Advanced Optimization