Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 61 ยท Performance and Quality

Theme Performance and Core Web Vitals

Make a Shopify theme fast: understand LCP, CLS and INP, load images and fonts correctly, tame render-blocking code and app scripts, and read speed reports.

A slow store loses sales quietly. Shoppers rarely complain about a page that takes five seconds; they just leave. Search engines also use real-user speed data as a ranking signal, so a heavy theme costs you twice. The good news is that most theme performance problems come from a short list of causes: one oversized hero image, scripts that block the page, fonts that cause the text to jump, and too many apps.

This lesson explains the three Core Web Vitals, shows the theme code that influences each one, and gives you a repeatable way to find problems. The real Liquid, HTML and CLI snippets are read-only (they only run on Shopify or in your own browser), and the TryIt blocks are honest stand-ins: small JavaScript programs that classify sample measurements and build image markup the way a theme would.

The thresholds below are the ones published for Core Web Vitals when this lesson was written. Google adjusts metrics from time to time (INP replaced an older input metric in 2024), so check the current definitions before you set a team target.

The three Core Web Vitals

Core Web Vitals measure what the shopper actually experiences, not how many kilobytes you shipped.

Metric Question it answers Good Needs improvement Poor
LCP (Largest Contentful Paint) How fast does the biggest visible thing appear? up to 2.5 s up to 4 s over 4 s
CLS (Cumulative Layout Shift) Does the page jump while loading? up to 0.1 up to 0.25 over 0.25
INP (Interaction to Next Paint) How quickly does the page react to taps and clicks? up to 200 ms up to 500 ms over 500 ms

A page is judged on the 75th percentile of real visits: if 75 percent of visits are good or better, the metric passes. That is why one fast test on your own laptop proves little. Real shoppers use mid-range phones on slow connections.

On a store, the usual culprits are:

  • LCP: the hero banner or main product image is large, loaded late, or lazy-loaded by mistake.
  • CLS: images without width and height, late-loading fonts, banners that appear after load, and app widgets injected above the content.
  • INP: large JavaScript bundles, many app scripts, and event handlers that do heavy work (for example, re-rendering a whole cart on every click).
flowchart LR
  A["Browser requests the page"] --> B["HTML arrives (Liquid already rendered)"]
  B --> C["CSS and blocking scripts"]
  C --> D["First paint"]
  D --> E["LCP image appears"]
  E --> F["Scripts run, page becomes interactive"]

Anything that delays steps C and E delays the metric shoppers feel most.

Where Shopify helps and where you do not

Shopify renders your Liquid on its servers and serves the HTML and assets through a CDN, so you do not tune servers. That puts the work in your hands in four places: the HTML your Liquid prints, the CSS and JavaScript in assets, the images and fonts you reference, and the apps the merchant installs. Section-level Liquid cost is covered separately in Liquid Performance.

Images: the biggest win

Images are usually the largest files on a page and the LCP element. Four rules cover most of the benefit.

1. Ask for the right size. Use the image_url filter with a width and let the browser pick from a srcset. The image_tag filter generates the srcset for you when you pass widths:

LIQUID
{{ section.settings.hero_image
  | image_url: width: 1600
  | image_tag:
    widths: '400, 800, 1200, 1600',
    sizes: '100vw',
    loading: 'eager',
    fetchpriority: 'high' }}

2. Mark the LCP image as important. The first big image above the fold should be loading="eager" with fetchpriority="high". Do not lazy-load it: lazy loading waits until layout to decide the image is visible, which delays the very image that defines LCP.

3. Lazy-load everything below the fold. Product grids, footers and carousel slides after the first one should use loading="lazy". Themes often pass a flag to the product card snippet so only the first row loads eagerly (see Snippets and the render Tag).

4. Reserve the space. Always output width and height (or an aspect-ratio in CSS) so the browser knows the box before the file arrives. image_tag adds the attributes when it knows the image dimensions. This is the cheapest CLS fix there is. Responsive image details are in Product Media.

Render-blocking CSS and JavaScript

A render-blocking resource stops the browser from painting until it is downloaded and processed. Stylesheets in the <head> block rendering by design. Scripts block parsing unless you tell the browser otherwise.

  • Load scripts with defer (runs after parsing, in order) or type="module" (deferred by default). Do not put a plain <script src> in the head.
  • Keep the critical CSS small. Split rarely used styles (a store locator, a size guide dialog) into files loaded only by the section that needs them. The {% stylesheet %} and {% javascript %} tags help here, as described in CSS for Themes.
  • Avoid libraries you do not need. A theme built on modern web components rarely needs jQuery, and every library you drop is bytes the shopper does not download.
  • Use preload sparingly. Preloading too many files makes them compete with each other.
LIQUID
<link rel="stylesheet" href="{{ 'base.css' | asset_url }}">
<script src="{{ 'theme.js' | asset_url }}" defer></script>

Fonts without jumps

Web fonts cause two problems: invisible text while the font loads, and a layout jump when the fallback is swapped for the real font. Reduce both:

  • Use font-display: swap (the font_face filter lets you pass font_display: 'swap') so text appears immediately in a fallback font.
  • Preload only the one or two font files used above the fold, with crossorigin.
  • Prefer a small number of weights. Each weight is another file.
  • Choose a fallback with similar proportions, or use size-adjust to match it, so the swap moves little.
LIQUID
{{ settings.type_body_font | font_face: font_display: 'swap' }}
<link rel="preload" as="font" type="font/woff2"
      href="{{ settings.type_body_font | font_url: 'woff2' }}" crossorigin>

Shopify-hosted fonts come from the same CDN as your assets, which avoids an extra connection to a third-party font service.

Apps and third-party scripts

Apps are the most common reason a fast theme becomes a slow store. Each app can add JavaScript, CSS, and extra network requests on every page, and you do not control their code. App embeds and tag-manager snippets run on pages where they may not even be needed.

A practical approach:

  1. Measure the store with all apps on, then with the heavy ones disabled in the theme editor. The difference is the app cost.
  2. Remove apps that are no longer used, and check that they left no code behind (see App Blocks and App Embeds).
  3. Prefer app blocks (loaded only where placed) over global app embeds when the app supports both.
  4. Load non-essential scripts after the shopper interacts or after the load event. Theme App Extensions and Third-Party Scripts covers the details.

Measuring: lab data and field data

Lab data comes from a controlled test, such as Lighthouse in Chrome DevTools or PageSpeed Insights. It is repeatable and gives a list of fixes, but it simulates one device. Field data comes from real visitors (the Chrome User Experience Report, shown in PageSpeed Insights, and Shopify's own reports in the admin). It is what search engines see.

Use both: lab data to find causes and confirm a fix, field data to know whether real shoppers improved. The Shopify admin also shows an online store speed score, which is a summary based on Lighthouse runs of key pages; treat it as a trend line, not a precise grade, because it can move when an app changes.

Terminal
# Run Lighthouse from the command line against a preview URL
npx lighthouse "https://your-store.myshopify.com/?preview_theme_id=123456789" --view

Always test the theme preview with the same apps and content as the live store; an empty development store is much faster than a real catalog.

Stand-in: classify real-user samples

The first stand-in turns raw samples into the verdict a report would show. It computes the 75th percentile of each metric and compares it with the thresholds in the table. The numbers are made up; the logic is how the field reports work.

JS Stand-in: 75th percentile and Web Vitals verdicts

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The output shows LCP and INP as "needs improvement" and CLS as "good", even though one visit had a CLS of 0.3. That is the point of using a percentile: a few terrible visits do not decide the grade, and neither does one lucky test.

Stand-in: build image markup the way a theme should

The second stand-in plays the role of image_url and image_tag. It builds a srcset, marks the first image eager with fetchpriority="high", lazy-loads the rest, and always includes dimensions. It prints markup you can compare with real theme output.

JS Stand-in: eager hero, lazy grid, reserved space

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice what is missing from the grid images: no fetchpriority, because only the one image that defines LCP deserves it. Giving high priority to everything is the same as giving it to nothing.

A short performance checklist

  • LCP image: eager, fetchpriority="high", correct sizes, not hidden behind JavaScript.
  • Every image has dimensions or an aspect ratio.
  • Scripts use defer or modules; nothing blocks the head except small critical CSS.
  • One or two font files preloaded, font-display: swap.
  • No unused libraries, no unused apps, no leftover app code.
  • Measured in the lab and in the field, on a throttled mobile profile.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which image on a page should get fetchpriority="high" and loading="eager"?

    Only the likely LCP image deserves the boost. Lazy-loading it would delay the metric, and boosting everything removes the benefit.
  2. 2. What is the most direct way to prevent layout shift from images?

    When the browser knows the box size before the file arrives, nothing moves when the image appears.
  3. 3. A store's p75 INP is 320 ms. What is the verdict?

    Good is up to 200 ms and poor is over 500 ms, so 320 ms falls in between.
  4. 4. Why use both lab and field data?

    A lab test is one simulated visit that you can repeat. Field data aggregates real devices and networks and is the signal that matters for ranking.

Summary

  • Core Web Vitals are LCP (loading), CLS (visual stability) and INP (responsiveness), judged at the 75th percentile of real visits.
  • Serve responsive images with srcset, make the LCP image eager with high priority, lazy-load the rest and always reserve space.
  • Defer scripts, keep critical CSS small and avoid libraries you do not need.
  • Load fonts with swap, preload only what is above the fold, and limit weights.
  • Apps often cost more than the theme: measure with and without them and remove what is unused.
  • Use lab tools to find causes and field data to confirm results.

Next, look at the cost of the Liquid itself in Liquid Performance: Loops, Objects and Limits.