# Speed & Core Web Vitals

> Keep your published app fast and stable on mobile by optimizing LCP, CLS, and INP, sizing media cleanly, limiting third-party scripts, and auditing in Lighthouse.

- Canonical: https://exaspark.ai/docs/page-speed-and-core-vitals/

## What Core Web Vitals measure and why they matter

Loading speed directly shapes both search rankings and conversion rates. Mobile visitors on cellular networks leave pages that stall before painting the hero, and mis-tap buttons when late images shove content downward.

Google evaluates real-user speed through three **Core Web Vitals**, judged primarily on mobile devices rather than fast desktop connections:

| Vital | What visitors feel | Good | Needs work | Poor | Top causes in web apps |
| --- | --- | --- | --- | --- | --- |
| **LCP** (Largest Contentful Paint) | How fast the hero headline or photo paints | `<= 2.5s` | `2.5s – 4.0s` | `> 4.0s` | Oversized hero PNGs, lazy-loaded heroes, slow fonts |
| **CLS** (Cumulative Layout Shift) | Visual stability while elements load | `<= 0.10` | `0.10 – 0.25` | `> 0.25` | Missing image dimensions, async cards shifting layout |
| **INP** (Interaction to Next Paint) | Responsiveness after a tap or click | `<= 200ms` | `200ms – 500ms` | `> 500ms` | Unpaginated lists, heavy third-party widgets, laggy inputs |

Published ExaSpark apps ship with automatic bundling, edge caching, and HTTPS. Most real slowdowns stem from raw multi-megabyte media, unsized containers, and heavy third-party scripts inside the app.

## Accelerating LCP (Largest Contentful Paint)

Your **LCP element** is almost always the hero photograph, product mockup, or primary headline visible above the fold.

- **Right-size hero imagery.** Resize hero visuals to `1200–1600px` wide and compress photos to **WebP** or JPEG under `150–250 KB`. Avoid uploading raw `5000px` photos or 4 MB PNGs.
- **Prioritize the hero, lazy-load everything below it.** Set `fetchpriority="high"` and eager loading on the above-the-fold hero—never `loading="lazy"`. Use `loading="lazy"` strictly for below-the-fold feature shots and galleries.
- **Trim font weights.** Load one or two font families using only active weights (`400`, `500`, `600`, `700`) with `font-display: swap` so headlines paint immediately.
- **Skip full-screen splash animations.** Hiding the hero behind a 1.5-second JavaScript fade adds directly to LCP.

```html
<!-- Above-the-fold hero: eager, high priority, explicit dimensions -->
<img
  src="/images/hero-studio.webp"
  alt="Studio booking calendar showing live court slots"
  width="1280"
  height="720"
  fetchpriority="high"
  decoding="async"
/>

<!-- Below-the-fold feature image: lazy-loaded with explicit dimensions -->
<img
  src="/images/feature-checkout.webp"
  alt="Instant Stripe checkout flow on mobile"
  width="960"
  height="640"
  loading="lazy"
  decoding="async"
/>
```

## Eliminating CLS (Cumulative Layout Shift)

Layout shifts occur when the browser renders text first and later learns how tall an image, database card, or banner is—pushing links out from under a user's thumb.

- **Declare explicit media dimensions.** Add `width` and `height` attributes (or CSS `aspect-ratio` containers) to every `<img>`, avatar, video poster, and iframe.
- **Match skeleton heights to loaded content.** Reserve realistic heights for async catalog cards, booking slots, or pricing blocks so sections stay locked in place as data resolves.
- **Keep banners and toasts out of document flow.** Render cookie notices or alerts as fixed overlays instead of inserting bars above your header after hydration.
- **Animate `transform` and `opacity`.** Avoid animating `height`, `top`, or `margin`, which trigger layout recalculations.

## Keeping INP (Interaction to Next Paint) snappy

An app that loads in 1.2 seconds still feels sluggish if tapping a filter, typing in search, or opening a drawer freezes mid-range phones.

- **Paginate database queries on the server.** Rendering 2,000 rows in the browser stalls mobile CPUs. Cap queries to `20–50` items per page; see [Search, filtering & pagination](https://exaspark.ai/docs/search-filtering-pagination/).
- **Debounce search inputs.** Wait `200–300ms` after typing pauses before running live search queries or table re-renders.
- **Limit third-party scripts.** Chat widgets, session recorders, social embeds, and stacked ad pixels clog the mobile main thread. Remove unused tags, load remaining scripts with `defer` or `async`, and delay chat widgets until user interaction.
- **Mount heavy modals on demand.** Render detail modals or drawers only when opened rather than mounting one per list row.

## Copy-paste prompts to optimize speed in ExaSpark

Use targeted prompts to clear rendering bottlenecks without altering your brand design.

To optimize a public landing page for LCP and CLS:

> **Example prompt (Web):** Optimize our landing page for Core Web Vitals: give the above-the-fold hero image explicit width/height and fetchpriority="high" without lazy loading, add loading="lazy" and explicit aspect-ratio wrappers to below-the-fold images, load only active font weights with font-display: swap, and remove any initial page-fade loader delaying the hero headline.

To tighten interactive speed (INP) on a data-backed app:

> **Example prompt (App):** Improve mobile responsiveness and INP across our catalog and dashboard: paginate database queries to 24 rows per page, debounce search input by 250ms, add fixed-height loading skeletons matching final cards to eliminate layout shift, and mount detail modals only when opened.

## Auditing your live site in Lighthouse and PageSpeed Insights

Always benchmark your **Live published URL** (`https://yourdomain.com` or `.exaspark.app`)—never your Preview workspace, which carries interactive workspace tooling instead of production caching.

1. **Publish your latest build** — Click **Publish** so production bundling and caching are active on Live.
2. **Open Live in Chrome Incognito** — Browser extensions inject scripts that skew Lighthouse scores; Incognito establishes a clean baseline.
3. **Run a Mobile Lighthouse audit** — Open Chrome DevTools (`F12`), select **Lighthouse > Mobile > Performance**, and run an analysis. Check **PageSpeed Insights** as well for real-world user data once traffic grows.
4. **Fix the top two bottlenecks** — Tackle the largest savings first—typically one oversized hero image, a blocking third-party script, or a layout-shifting block.
5. **Republish and watch live metrics** — Re-run Lighthouse after publishing and track real user load times in [Analytics & live health](https://exaspark.ai/docs/analytics/).

> **Note:** Focus on landing cleanly in the **Good** green thresholds (`LCP <= 2.5s`, `CLS <= 0.1`, `INP <= 200ms`) on Mobile rather than stripping helpful features to chase a synthetic `100/100`.

## Speed troubleshooting matrix

| Symptom | Root cause | Practical fix |
| --- | --- | --- |
| **Mobile LCP exceeds 3.5s** | Multi-MB hero image or `loading="lazy"` on hero | Resize under `1600px`, convert to WebP (`< 200 KB`), remove `loading="lazy"`, add `fetchpriority="high"` |
| **CLS exceeds 0.15** | Unsized images or late-loading banner/cards pushing content | Add `width`/`height` or `aspect-ratio` and match async skeleton heights |
| **Desktop 96 vs Mobile 58** | Mobile CPU throttling exposes heavy scripts or oversized media | Defer third-party widgets, compress hero images, and paginate long lists |
| **Taps and search lag (high INP)** | Main thread blocked by huge DOM lists or synchronous filters | Move filtering/pagination server-side and debounce search by 250ms |
| **Text flashes blank on load** | Custom web font blocks render or loads unused weights | Set `font-display: swap` and load only 2–4 active font weights |
| **Smooth on laptop, sluggish on phone** | Heavy full-bleed videos or oversized photos straining mobile GPUs | Inspect viewports in [Browser Device Lab](https://exaspark.ai/docs/device-lab/) and swap hero video for a crisp poster |

## Next steps

- [Sitemaps, robots & schema](https://exaspark.ai/docs/technical-seo-and-sitemaps/) — Pair fast Core Web Vitals with clean sitemaps and JSON-LD.
- [Analytics & live health](https://exaspark.ai/docs/analytics/) — Monitor real visitor loading speed, uptime, and runtime errors.
- [Search, filtering & pagination](https://exaspark.ai/docs/search-filtering-pagination/) — Keep database-backed views snappy as row counts grow.

## From the blog

- [How to make a website load faster](https://exaspark.ai/blog/how-to-make-a-website-load-faster/) — Practical speed wins that lift Core Web Vitals and conversions.
- [SEO and GEO for a new website](https://exaspark.ai/blog/seo-and-geo-for-a-new-website/) — See how mobile speed supports search and AI discovery.
- [What is responsive design?](https://exaspark.ai/blog/what-is-responsive-design/) — Build mobile-first layouts that render fast on every screen size.
