Build a Shopify theme from scratch, with Liquid · Part 6 of 6
Performance, accessibility, Theme Check and publishing
Lighthouse behind a store password, the audits that fired and the one-line fixes, why mobile scores on a slow laptop cannot be trusted, every Theme Check rule on and clean, and the three ways a theme ships: a zip, theme publish, and the Theme Store.
By Abhishek Fouzdar
The last part measures the theme, fixes what the measurements show, turns every Theme Check rule on, and ships it: a zip a merchant can upload, a release on GitHub, and the theme published on the store. Part 5 built search, pagination, metafields and the Hindi locale.

Measuring behind a password
The store is password-protected, and Lighthouse does not know the password. The CLI's --extra-headers flag can carry a cookie, but Shopify's storefront session cookie did not get the audit past /password; what worked was Lighthouse's node API with a Chrome that had already logged in. Lighthouse opens its pages in the same browser, so the session comes along:
import lighthouse from 'lighthouse'
import desktopConfig from 'lighthouse/core/config/desktop-config.js'
import * as chromeLauncher from 'chrome-launcher'
import puppeteer from 'puppeteer-core'
const chrome = await chromeLauncher.launch({ chromeFlags: ['--headless=new'] })
const browser = await puppeteer.connect({ browserURL: `http://localhost:${chrome.port}` })
const page = await browser.newPage()
await page.goto(`${store}/password`)
await page.type('input[type=password]', process.env.STOREFRONT_PASSWORD)
await Promise.all([page.waitForNavigation(), page.click('button[type=submit]')])
await page.goto(`${store}/?preview_theme_id=${theme}&pb=0`) // sets the preview cookie once
await page.close()
const result = await lighthouse(`${store}/products/ajrakh-cushion-cover?pb=0`, { port: chrome.port, output: 'json' }, form === 'desktop' ? desktopConfig : undefined)
Shopify's own guidance for the audit is in there: pb=0 hides the preview bar, which otherwise adds an iframe and a script to every page, and the three pages that matter are home, product and collection. The first visit with preview_theme_id sets a cookie so the audited URLs can leave the parameter off; with it, every page is a redirect and Lighthouse charges the theme for it.
Three more things the script does that a single run in DevTools would not. It runs each page five times and takes the median, because single Lighthouse runs vary. It records environment.benchmarkIndex, Lighthouse's measure of how fast the machine running it is. And it pulls the failing audits out of the JSON instead of reading six reports by hand.
What the first run said
| Page | Mobile | Desktop | Accessibility | Best practices | SEO |
|---|---|---|---|---|---|
| Home | 72 | 99 | 93 | 100 | 92 |
| Product | 68 | 100 | 100 | 96 | 100 |
| Collection | 84 | 99 | 95 | 78 | 100 |
Desktop was already fine. The audits behind the rest, in the order they were fixed:
color-contrast on the home and collection pages: the struck-through compare-at price. Part 2 had styled it text-ink-2/70, muted ink at 70% opacity, which lands at 3.16:1 on the cream background; small text needs 4.5:1. Full text-ink-2 is 5.9:1. One class.
image-redundant-alt on the home page: the collection tiles. Each tile's image had alt: title and the tile's text was the same title, so a screen reader said "Bedding, Bedding". The image's alt is now empty; the link text names the collection.
heading-order on the collection page: the h1 was followed by h3s, because the product card hard-coded its title as <h3>. The right level depends on where the card sits, h2 under a page's h1, h3 under a section's h2, so the card takes it as an argument and defaults to h3:
{%- assign heading = heading | default: 'h3' -%}
<{{ heading }} class="mt-3 text-base font-semibold leading-snug group-hover:text-accent">{{ product.title }}</{{ heading }}>
lcp-discovery-insight, on every page: "fetchpriority=high should be applied". The largest contentful paint is an image on all three pages, the hero, the product's first photo, the first card, and each was eager and in the HTML but not prioritised. image_tag takes fetchpriority: 'high', and that is the one attribute that moves LCP without moving anything else.
uses-responsive-images, 221 KiB on the product page on mobile. The gallery's sizes said 100vw and the image is 100vw minus the page padding; at a phone's pixel ratio the browser picked the next width up from a 600, 900, 1200, 1400 set. sizes now says calc(100vw - 48px) and the set has more steps. The card got the same treatment, with a fixed 310px at the widest layout, where the grid stops growing.
meta-description on the home page is the one audit left. The home page's description is the merchant's, set in Online Store → Preferences, and this store's is empty; a theme can output it but not invent it.
errors-in-console, third-party-cookies and uses-long-cache-ttl were Shopify's own scripts, a metrics endpoint refused by CORS in headless Chrome and the preview's theme-hot-reload.js, which the published theme does not load. Not the theme's, and gone from a published-theme audit.
Two additions the audits did not ask for but a keyboard user would. A single :focus-visible style, an accent outline, so that every link, button and input shows focus the same way without showing it on mouse clicks. And prefers-reduced-motion, which turns off the drawer's slide and the gallery's smooth scroll for anyone who asked their OS for less motion.
What the second run said
| Page | Mobile | Desktop | Accessibility | Best practices | SEO |
|---|---|---|---|---|---|
| Home | 67 | 97 | 100 | 100 | 92 |
| Product | 50 | 93 | 100 | 100 | 100 |
| Collection | 54 | 99 | 100 | 100 | 100 |
Accessibility and best practices are 100 across the board, LCP's priority check passes on every page, and the responsive-images savings on the product page dropped from 221 to 67 KiB. The mobile performance numbers went down, and that needs explaining rather than hiding.

Lighthouse's mobile score simulates a slow phone by throttling the CPU of the machine it runs on, and it calibrates that throttling against the machine's speed, which it reports as benchmarkIndex. Across the five product-page runs on this laptop the index ranged from 496 to 628; Lighthouse's own guidance treats values below about 1000 as a machine too slow to simulate a mobile device faithfully, and warns that scores on such hosts run low and noisy. The five mobile product scores were 49, 49, 50, 62 and 69: a spread of twenty points with no code change between them. The desktop preset applies no CPU throttling and its five runs sat between 90 and 99.
The metric that moves the mobile score is total blocking time, and on these pages that is main-thread work from scripts the theme does not ship: Shopify's analytics and perf-kit bundles, loaded by content_for_header, come to about two seconds of CPU under the throttle, against six kilobytes of theme JavaScript. The LCP image loads within a few hundred milliseconds of the request and then waits for the main thread to paint it. The fixes above are what a theme can do about LCP; the remainder is Shopify's and the host's, and the honest number for the theme's own work is desktop 93 to 99.
The Theme Store's bar is a Lighthouse performance average of 60 across the three pages, mobile and desktop, measured on Shopify's infrastructure rather than an eight-year-old laptop. Desktop clears it by thirty points; mobile on this machine does not clear it and cannot be trusted either way. The way to know is to run the audit on a machine with a benchmark index above a thousand, or let Shopify's reviewers run theirs.
Every Theme Check rule
Theme Check has been running since part 1 on its recommended set. The all configuration enables every check the tool has, 85 of them in the current release, including the opinionated ones about asset sizes, remote assets, parser-blocking scripts, hard-coded routes, undefined objects, deprecated filters and schema details:
extends: theme-check:all
53 files inspected with no offenses found.
That passed on the first run, which is less a boast than a consequence of the series: each part ran the recommended checks before pushing, the stylesheet is a single compiled file of 24 KiB against a 100 KiB AssetSizeCSS threshold, the script is deferred, every URL comes from routes, every string from t, and the fonts from the font picker. A theme that reaches 1.0 with all clean can keep it clean in CI with shopify theme check --fail-level error, and the exit code does the rest.
Shipping
Three ways a theme reaches a store, and the theme does all three.
A zip. shopify theme package reads theme_name and theme_version from config/settings_schema.json, honours .shopifyignore, and writes Lantern-1.0.0.zip: 61 files, 52 KB, no src/, no node_modules, no package.json. A merchant uploads it under Online Store → Themes → Add theme → Upload zip file, and that is the whole installation. The zip is attached to the v1.0.0 release of the repository.
A push. shopify theme push has been the deploy since part 1, always to the unpublished "Lantern (dev)" theme. Publishing it is one more command:
shopify theme publish --theme 209640391025
Lantern (dev) [live] #209640391025
Horizon [unpublished] #195832611185
The store's storefront is now Lantern, with no preview_theme_id and no preview bar:

For a store that is not a development store the usual shape is shopify theme push --unpublished from CI on every merge, a look at the result, and theme publish by a person. Shopify's GitHub integration is the alternative that keeps the two in sync without CI at all: connect a branch to a theme and every commit pushes, every editor change commits back. It is the right choice for an agency that owns a merchant's theme and the wrong one for a theme developed for many stores, because the editor's commits land in the branch.
The Theme Store. A theme sold there goes through Shopify's review, and the published requirements read like this series' table of contents: JSON templates and section groups, theme blocks, the font picker, t for every string with the locale files complete, Theme Check clean, Lighthouse above 60, accessibility to WCAG 2.1 AA, no external scripts, no frameworks loaded from a CDN, and a demo store. The requirements that would still be work for Lantern are the ones a series cannot do for a theme: a range of presets, a documentation site, a support address, and the kind of testing that only comes from the second store, the third, and the one with four thousand variants.
What went wrong
The image preload lost the priority hint. image_tag has a preload: true parameter that sends a Link header with rel=preload, imagesrcset and imagesizes, which is the right way to preload a responsive image. With it on, Lighthouse's LCP checklist still said the request was not priority-hinted, because the browser fetched the image from the Link header, which carries no fetchpriority, and the <img> with fetchpriority="high" found it already in flight. The image was in the initial HTML anyway, so the preload bought nothing and cost the hint. preload came off the three images and the check turned green.
The first Lighthouse runs audited the password page. Every score was 99, every LCP element was <p class="description">, and the run warnings said the URL had redirected. A score that good on a first run is a reason to read the report.
theme package warned about nothing and included everything in .shopifyignore's complement, which is the correct behaviour and the reason .shopifyignore has src/* and node_modules/* in it since part 1: the zip has no build tooling, and a merchant who uploads it gets a theme, not a repository.
That is the series. The main post is the overview and the index, the theme is at shipbytes/lantern-theme with one commit per part, and the store it was built on is still there with its forty products, its seventeen collections and, since part 5, its Hindi.
New posts by email
Get new posts by email. Nothing else, no digests, unsubscribe in one click.
Comments
Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.
In this series
6 / 6- OverviewBuild a Shopify theme from scratch, with Liquid
- Part 1The anatomy of a theme, and one that renders
- Part 2Liquid on the product and collection pages
- Part 3Sections, blocks and the theme editor
- Part 4Variants without reloads, the Cart API and a cart drawer
- Part 5Search, pagination, metafields, translations and customers
- Part 6Performance, accessibility, Theme Check and publishing