CMS and e-commerce platforms
Speed up a WordPress or Shopify store you didn't write: find what each plugin and app adds, load app scripts without blocking, and use the platform's cache.
- 01Find who added each fileTrace every script and stylesheet on a platform page back to the theme or plugin that asked for it, and remove what the page doesn't use.
- 02Load apps without blocking the pageTell a pasted script tag from an app block or an async script, and measure what each one costs the first paint.
- 03Use the platform, and know its limitsPut a page cache and a CDN to work, know what they can't speed up, and tell what you can change on WordPress and on Shopify.
Kiran's Mint tea page, built from other people's code
Module 36 looked at speed through each framework's own tools. This last lesson looks at platforms: ready-made systems that run a whole site for you. WordPress and Shopify are the best known.
Ravi's cousin Kiran sells his teas in her town. She built her shop in a weekend, on WordPress with WooCommerce, its shop plugin. She picked a theme for the look. She added plugins for a wishlist heart, size buttons and a contact form. She didn't write a line of code.
Asha opens Kiran's Mint tea page on her phone. The screen stays blank. Then the words appear, but no photo. The photo comes last. Here is Asha's screen, second by second, before and after the fixes in this lesson:
Kiran didn't write this code. So can she fix it? Mostly, yes. The course timed both versions:
// Asha's visits to Kiran's Mint tea page. Times in ms after she asked for it.// JavaScript in kB, as it came over the network, compressed (1 kB = 1,000 bytes).const before = { firstByte: 2489, photo: 3692, javascript: 416.5, requests: 58 };const after = { firstByte: 355, photo: 1292, javascript: 130.4, requests: 39 }; for (const [name, visit] of [["Before", before], ["After", after]]) { console.log(`${name}: first byte ${visit.firstByte} ms, photo ${visit.photo} ms, ${visit.javascript} kB of JavaScript, ${visit.requests} requests`);}- Lines 1 and 2 are comments. A millisecond (ms) is a thousandth of a second. A kB is 1,000 bytes. Compressed means the size as the file travels over the network.
- Line 3 is the page as Kiran set it up. Line 4 is the same page after her fixes.
- Line 7 prints
Before: first byte 2489 ms, photo 3692 ms, 416.5 kB of JavaScript, 58 requests. Then it prints the same line for After.
The photo came 2,400 ms sooner. The page brought 286 kB less JavaScript. Yet Kiran changed no code in WordPress, WooCommerce or her theme. She changed what was on the page, and who answered it. After her fixes, a page cache answered Asha: a stored copy of the finished page, so WordPress didn't have to build it again. Why it matters: on a platform, you rarely rewrite code. You choose what runs, and where it comes from.
Kiran rents a furnished flat. The building and the furniture came with it, and she plugged in a few gadgets of her own. Her electricity bill is high. She can't rebuild the walls. But she can find which gadget uses the most power, unplug the ones she never uses, and ask about the boiler.
- In real life: The building
- In JavaScript: The platform: WordPress and WooCommerce, or Shopify
- In real life: The furniture that came with the flat
- In JavaScript: The theme: the page's look, and its own files
- In real life: The gadgets she plugged in
- In JavaScript: Plugins and apps, each adding its own files
- In real life: The landlord's boiler
- In JavaScript: The server and its caches
On a platform, most of the code on your page was written by others: the platform, the theme, and every plugin or app. You make it fast by finding who added each file, keeping only what the page needs, and letting the platform's caches answer for you. The next four sections take one part each.
How the course recorded it
- Kiran's shop: real WordPress 7.1.4, WooCommerce 11.3.0, the Astra theme 4.14.3, and three plugins from wordpress.org: Contact Form 7, YITH WooCommerce Wishlist, and Variation Swatches for the size buttons.
- Running it: WordPress Playground's command line, version 3.1.64, ran the shop on the course's laptop. Playground runs PHP inside WebAssembly, with SQLite as the database. That's slower than a normal host. So its server times show that WordPress built a page, not how fast a host would.
- Asha's phone: Chrome 157, with the CPU 4 times slower, on Lighthouse's phone screen. The course's server played a Fast 4G line: 3 round trips to open each new connection, then 165 ms before each answer, then 8.1 megabits a second.
- Four versions: the page as Kiran set it up, the page after her fixes with a page cache, and two more with a review app added two ways. A small plugin of the course's switched between them for each visit.
- Real input: Asha's tap on Add to cart was a mouse press and release, sent through Chrome's DevTools protocol, one second after the photo appeared.
- 5 visits of each version, taking turns. The lesson quotes the visit with the middle LCP, unless it says otherwise.
Themes and plugins add files to every page
WordPress builds each page with PHP, a language that runs on the server. A theme decides how the page looks: its templates and its CSS. A plugin adds a feature, like a shop or a form. Both can add files to the page. Here is how a plugin adds a script, in its simplest form:
<?php// A plugin's main file runs on every request.add_action('wp_enqueue_scripts', function () { wp_enqueue_script('contact-form', plugins_url('form.js', __FILE__));});- Line 2 is a comment. WordPress runs every active plugin's main file on every request.
- Line 3 hooks into
wp_enqueue_scripts. That's the moment WordPress collects the files for a page. - Line 4 calls
wp_enqueue_script. It puts form.js on the list, and WordPress prints a script tag for it.
Nothing here asks whether the page has a form. So the script goes on every page. Contact Form 7's docs say it works this way: "In its default settings, Contact Form 7 loads its JavaScript and CSS stylesheet on every page."
A restaurant has a few cooks. Each cook has a side dish, and a rule: put mine on every table. So every table gets bread, soup and salad, even the one that only ordered tea. The tables fill up, and the tea takes longer to arrive.
- In real life: A cook's side dish
- In JavaScript: A plugin's script or stylesheet
- In real life: The rule "on every table"
- In JavaScript: wp_enqueue_script with no check for the page
- In real life: The table that only ordered tea
- In JavaScript: The Mint tea page, which has no form
- In real life: "Only when someone orders it"
- In JavaScript: Loading a plugin's files only on pages that use them
Who asked for each file?
To find out, the course asked WordPress itself. A small plugin listed every script and stylesheet WordPress printed for the Mint tea page, with the files each one needs. Then each file could be traced back to the theme or plugin that asked for it. Here is the JavaScript, by who asked:
The wishlist heart asked for 277.5 kB of the 416.5 kB. That's two thirds of the page's JavaScript. Its button is built with React and a toolkit of its own. So WordPress also sent React, ReactDOM, Lodash and Moment from its own library. And on every page view, the button asked WordPress for wishlists twice. It used WordPress's REST API, the way scripts ask WordPress for data. Each of those calls ran PHP too. Why it matters: one small feature can bring a whole framework with it. Measure a plugin before you decide it's cheap.
Pick a theme or plugin to see its files:
- JavaScript files10
- JavaScript, compressed277.5 kB
- CSS files4
- CSS, compressed12.8 kB
- The filesdist/deprecated.min.js, vendor/moment.min.js, dist/date.min.js, vendor/lodash.min.js, vendor/react.min.js, date/index.js, styles/index.js, components/index.js, vendor/react-dom.min.js, add-to-wishlist/index.js, css/jquery.selectBox.css, css/prettyPhoto.css, css/style.css, frontend/add-to-wishlist.css
- After Kiran's fixesGone
Pick a theme or plugin. You see the scripts and stylesheets it asked for on the Mint tea page, as Kiran first set it up, and whether they were still there after her fixes.
Kiran's two fixes
First, the wishlist. Hardly anyone used it, so Kiran deactivated the plugin on WordPress's Plugins screen. Its files and its calls went with it. Second, the contact form. She still wants it, but on the contact page only. Contact Form 7 has a switch for that:
<?phpadd_filter('wpcf7_load_js', '__return_false');add_filter('wpcf7_load_css', '__return_false');add_action('wp_enqueue_scripts', function () { if (is_page('contact')) { wpcf7_enqueue_scripts(); wpcf7_enqueue_styles(); }});- Lines 2 and 3 use the plugin's own filters,
wpcf7_load_jsandwpcf7_load_css. A filter is a hook that lets your code change a value before WordPress uses it. Returning false turns the files off on every page. - Lines 4 to 9 put them back on one page. Line 5 checks for the page called contact. Lines 6 and 7 ask for the form's script and stylesheet.
A plugin without its own switch can still be limited. wp_dequeue_script and wp_dequeue_style take a file off the list, by its handle: the name the plugin gave it in WordPress.
After both fixes, the page had 27 JavaScript files instead of 39: 130.4 kB instead of 416.5 kB. Its CSS went from 49.8 kB to 35.6 kB.
What WordPress already does for you
Not everything needs fixing. Here is the photo's tag, as WordPress printed it:
<img src=".../mint-tea-600x400.jpg" width="600" height="400" srcset="... 600w, 300w, 1024w, 768w, 1536w, 1600w" sizes="(max-width: 600px) 100vw, 600px" fetchpriority="high" decoding="async" alt="Mint tea">- Line 3 gives the photo's width and height, so its space is kept before it arrives.
- Line 4 is
srcset: the photo in six widths. WordPress and WooCommerce made the smaller ones when Kiran uploaded it. The 1600 px one is her original. Line 5,sizes, tells the browser how wide the photo will be shown. Asha's phone picked the 768 px file: 19.3 kB. - Line 6 is
fetchpriority="high". Since WordPress 6.3, WordPress adds it to the image it thinks will be the LCP. Chrome then asks for it early.
Scripts too. WordPress 6.3 added a strategy setting to wp_enqueue_script, for defer or async. WooCommerce uses it: 10 script tags on Kiran's page had defer. And since WordPress 6.9, WordPress loads the CSS of only the blocks a page uses, even with a classic theme like Astra.
One download the fixes missed
Look at the photo files the page downloaded. Both versions downloaded two of them. One was the 768 px photo Asha saw. The other was the full 1600 px original: 102.8 kB, more than five times bigger. The gallery's zoom asked for it, so it can show the photo large.
// WooCommerce: is the gallery's zoom on? The theme decides.'zoom_enabled' => apply_filters('woocommerce_single_product_zoom_enabled', get_theme_support('wc-product-gallery-zoom')), // A line in a small plugin of Kiran's: no zoom, so no full-size photo.add_filter('woocommerce_single_product_zoom_enabled', '__return_false');- Line 2 is from WooCommerce 11.3.0, line 653. The zoom is on when the theme says it supports zoom. Astra says it does.
- Line 5 is a filter that turns the zoom off. WooCommerce's gallery script then skips the zoom, and its download.
Why it matters: a theme can switch on features you never asked for. Check every image request, not only the images you can see.
Apps and injected scripts
Shopify calls its add-ons apps. Many plugins and apps add a script that comes from another company's server. That's a third party, like the tags in lessons 24.1 to 24.3. What changes is how the script gets into the page.
Kiran tries a review app. It shows the stars under the tea's name. Its install guide says: paste this tag at the top of your theme's head. On WordPress, that takes a few lines:
<?phpadd_action('wp_head', function () { echo '<script src="https://apps.example/star-reviews.js"></script>';}, 1);- Line 2 hooks into
wp_head, where WordPress prints the head. The 1 on line 4 makes it run early, so the tag lands near the top. - Line 3 prints a plain script tag.
The other way asks WordPress for the same file, with the async strategy:
<?phpadd_action('wp_enqueue_scripts', function () { wp_enqueue_script('star-reviews', 'https://apps.example/star-reviews.js', array(), null, array('strategy' => 'async'));});Line 3 adds array('strategy' => 'async'). Here are the two tags WordPress printed:
<!-- Pasted at the top of the head: -->
<script src="https://apps.example/star-reviews.js"></script>
<!-- Enqueued with the async strategy: -->
<script async data-wp-strategy="async" id="star-reviews-js" src="https://apps.example/star-reviews.js"></script>Line 2 is the pasted tag. Line 5 is WordPress's: the same file, with async. A plain script tag stops the browser. It can't read the rest of the HTML until the script has arrived and run. async lets it keep reading, and the script runs whenever it arrives. And this script lives on another server, so Asha's phone must open a new connection first.
A shop opens at nine. One morning the owner says: we don't open until the van from the next town arrives. Customers wait at the locked door. The next day she opens at nine, and unpacks the van whenever it comes.
- In real life: The locked door
- In JavaScript: The page, which can't paint yet
- In real life: The van from another town
- In JavaScript: The app's script, from the app's own server
- In real life: "Not until the van arrives"
- In JavaScript: A plain script tag at the top of the head
- In real life: Unpacking whenever it comes
- In JavaScript: async: the script runs when it arrives
// The review app's script, two ways. The middle of five visits each, in ms.const blocking = { scriptArrived: 716, firstPaint: 904, photo: 1380 };const nonBlocking = { scriptArrived: 1040, firstPaint: 744, photo: 1244 }; console.log(`Blocking: first paint ${blocking.firstPaint} ms, photo ${blocking.photo} ms`);console.log(`Async: first paint ${nonBlocking.firstPaint} ms, photo ${nonBlocking.photo} ms`);console.log(`The wait for the script: ${blocking.firstPaint - nonBlocking.firstPaint} ms`);- Line 2 is the pasted tag. Line 3 is async. Each holds the middle of five visits.
- Lines 5 to 7 print
Blocking: first paint 904 ms, photo 1380 ms,Async: first paint 744 ms, photo 1244 msandThe wait for the script: 160 ms.
With the pasted tag, the first paint waited 160 ms longer, and the photo 136 ms. It wasn't luck: the slowest async visit painted at 884 ms, before the fastest blocking visit, at 904 ms. The stars came at about the same time either way, because the app asks its server for the reviews only once the HTML has been read. Why it matters: one tag at the top of the head made every visitor wait before anything appeared. A slower app server makes the wait longer.
Apps on Shopify
Shopify gives apps two ways in. The old one is Shopify's ScriptTag API, which isn't the HTML tag: the app asks Shopify to add its script to the store's pages. Shopify's docs say these scripts "load independently of theme control", and advise: "Ask the app developer to use defer if a script blocks rendering." Shopify has now deprecated the ScriptTag API.
The new way is theme app extensions:
- An app block is a part of the page that the store owner adds, moves or removes in the theme editor.
- An app embed block can add a script with nothing to see. Shopify adds it "by adding a
<script async>tag in the<head>", and only on pages where the block is on. - When the app is uninstalled, its blocks are "automatically and entirely removed". An app that pasted code into theme files can leave it behind.
Shopify also sets a limit for apps with its Built for Shopify badge: "Your app must not reduce the storefront Lighthouse performance score by more than ten points." Why it matters: on any platform, ask how an app loads its script before you install it, and measure the page after.
Pick a version to see all four side by side:
- Who answered the pageWordPress, with PHP
- First byte2,489 ms
- First paint2,988 ms
- First paint, middle of five visits2,988 ms
- The photo, the LCP3,692 ms
- JavaScript, compressed416.5 kB
- CSS, compressed49.8 kB
- Requests before the tap58
- Tap to the next paint13.7 ms
- Tap to the next page3,730 ms
Pick a version. Asha opened the Mint tea page, and tapped Add to cart a second after the photo appeared.
Platform caching and CDNs
Back to the first byte. Before the fixes, it came at 2,489 ms. WordPress built the page from scratch for every visit: PHP ran the theme and every plugin, and read the database. A page cache keeps a copy of the finished page. The next visitor gets the copy, and PHP doesn't run at all. Many hosts run one in front of WordPress, and caching plugins do the same job.
A bakery bakes its bread before it opens, and puts the loaves on the shelf. A customer takes one and pays. Nobody waits for the oven. But a birthday cake with a name on it is baked to order, every time.
- In real life: Baking a loaf
- In JavaScript: PHP building the page
- In real life: The loaves on the shelf
- In JavaScript: The page cache's copies
- In real life: Taking a loaf and paying
- In JavaScript: A visit the cache answers
- In real life: A birthday cake with a name on it
- In JavaScript: A page with one visitor's cart in it
// Asha's first byte, in ms. "built" is how long WordPress worked on the page.const before = { answeredBy: "WordPress", built: 2321, firstByte: 2489 };const after = { answeredBy: "the page cache", built: 0, firstByte: 355 }; for (const visit of [before, after]) { console.log(`${visit.answeredBy}: built in ${visit.built} ms, first byte at ${visit.firstByte} ms`);}- Line 2 is the first version: WordPress worked 2,321 ms on the page.
- Line 3 is after the fixes: a page cache in front of WordPress answered.
- Line 6 prints
WordPress: built in 2321 ms, first byte at 2489 msandthe page cache: built in 0 ms, first byte at 355 ms.
Remember, Playground is slower than a real host. So read the gap, not the 2,321 ms. With the cache, no PHP ran. The first byte came as soon as Asha's connection was open and the answer had crossed her network. Why it matters: on a slow server, a page cache is often the biggest single fix. WordPress's Site Health screen checks for one. It also times the server, and counts an answer under 600 ms as good (class-wp-site-health.php, line 3744).
What a cache can't answer
Then Asha taps Add to cart. That isn't a page view. It sends a POST, a request that changes something: here, her cart. No cache may answer a POST. WooCommerce's docs also say to keep the Cart, Checkout and My Account pages out of the cache, and visitors with cookies like woocommerce_items_in_cart. Once Asha has a cart, her later page views skip the cache too.
Here is the rule the course's page cache followed, shortened to its two tests:
// May the page cache answer this request?function fromCache(request) { if (request.method !== "GET") return false; return !request.cookies.includes("woocommerce_items_in_cart");} console.log(fromCache({ method: "GET", cookies: "" }));console.log(fromCache({ method: "POST", cookies: "" }));console.log(fromCache({ method: "GET", cookies: "woocommerce_items_in_cart=1" }));- Line 3 sends anything but a GET to WordPress.
- Line 4 does the same for a GET from a visitor with a cart.
- Lines 7 to 9 print
true,falseandfalse.
WooCommerce answered the POST with the Mint tea page again, with a notice: Mint tea has been added to your cart. So how long did Asha wait for that next page?
// From Asha's tap on Add to cart, in ms: to the next paint, and to the next page.const before = { tap: 13.7, nextPage: 3730 };const after = { tap: 11.6, nextPage: 2399 }; console.log(`Before: the tap painted in ${before.tap} ms, the next page came at ${before.nextPage} ms`);console.log(`After: the tap painted in ${after.tap} ms, the next page came at ${after.nextPage} ms`);- Line 2 is before the fixes. Line 3 is after. Both count from the tap.
- Line 5 prints
Before: the tap painted in 13.7 ms, the next page came at 3730 ms. - Line 6 prints
After: the tap painted in 11.6 ms, the next page came at 2399 ms.
The tap itself was quick both times, far inside INP's 200 ms (lesson 26.1). By then the page's scripts had finished. The wait was the next page, built by PHP every time. Before the fixes, it waited longer. When the tap's request came, three other PHP requests were still running: the wishlist's two calls, and the tab's icon. The course's WordPress ran two PHP requests at a time, so the tap's request waited its turn. Why it matters: a page cache speeds up pages, not carts. Keep the PHP work on every request small.
CDNs, and what the platforms do for you
A CDN keeps copies of files on servers around the world, close to visitors (lesson 15.4). On WordPress, you add one yourself. WordPress's handbook says some CDNs also cache whole pages, which it calls "Full Page Caching (FPC) or Edge Caching".
Shopify does this for every store. Its docs list:
- a CDN "backed by Cloudflare", with files compressed with Brotli and gzip, sent over HTTP/3;
- a server built only to render store pages, the Storefront Renderer;
- HTML sent in two parts, so the browser can start on the head early;
- 103 Early Hints for the files the head needs;
- speculation rules, which let the browser fetch a page before the visitor gets there.
WordPress now adds one of these to most sites too. Since WordPress 6.8, it adds speculation rules that fetch a link's page as a visitor starts to click it. Kiran's page had them. They're on only for visitors who aren't logged in, on sites with readable addresses like /product/mint-tea/ (speculative-loading.php, lines 26 to 28).
The platforms in the field
So which platform is fastest for real visitors? HTTP Archive's Technology Report looks at millions of sites. It finds which platform each site runs on, and joins that with CrUX, Chrome's field data (lesson 10.1). A site is good for a metric when at least 75% of its visits were good.
// HTTP Archive's Technology Report, phones: [sites with a good TTFB, sites measured].const ttfb = { WordPress: [570682, 2413384], WooCommerce: [64186, 500596], Shopify: [373779, 437688],}; for (const [platform, [good, measured]] of Object.entries(ttfb)) { console.log(`${platform}: ${((good / measured) * 100).toFixed(1)}% of ${measured.toLocaleString("en")} sites`);}- Lines 3 to 5 hold, for each platform, the sites with a good TTFB and the sites measured, on phones.
- Line 9 prints one line for each:
WordPress: 23.6% of 2,413,384 sites, then the same for WooCommerce and Shopify.
Only 12.8% of WooCommerce sites had a good TTFB, against 85.4% of Shopify sites. Every Shopify store gets Shopify's servers and cache. A WordPress site gets whatever its owner set up. For all three Core Web Vitals, 49.0% of WordPress sites passed, 40.6% of WooCommerce sites, and 76.5% of Shopify sites. Why it matters: these are shares of many sites. Your own numbers depend on your host, your theme and your plugins, as Kiran's did.
Pick a platform to see its numbers:
- Sites with Core Web Vitals data2,513,839
- Pass all three Core Web Vitals49.0%
- Good LCP56.3%
- Good INP90.0%
- Good CLS87.6%
- Good TTFB23.6%
Pick a platform. You see how many of its sites HTTP Archive found, and the share of them whose real visitors had good Core Web Vitals and a good TTFB.
What you can and can't change
Ravi has been watching. Should he move his own shop to Shopify? First he wants to know what he would still control.
At a covered market, the market runs the roof, the lights and the doors. You set out your stall: what you sell, and how it looks. In your own shop, you choose everything, down to the heating. But when the boiler breaks, you fix it.
- In real life: The market's roof, lights and doors
- In JavaScript: Shopify's servers, cache and CDN
- In real life: Your stall: your goods and your display
- In JavaScript: Your theme and your apps
- In real life: Your own shop
- In JavaScript: WordPress on a host you choose
- In real life: Fixing your own boiler
- In JavaScript: Setting up your own cache and CDN
Read each row across: one part of a site, and who controls it on each platform.
| What | WordPress on your own host | Shopify |
|---|---|---|
| The server and the page cache | Yours to choose: the host, a caching plugin, or both. | Shopify's. Its servers and its cache come with every store. |
| The CDN | Yours to add, for files and even whole pages. | Shopify's own CDN, backed by Cloudflare, for every store. |
| The theme's code | Every file: PHP, CSS and JavaScript. | Every file: Liquid, CSS and JavaScript. |
| Plugins or apps | Yours to add, remove, or limit to some pages. | Yours to install and remove. App blocks go wherever you place them. |
| The platform's own scripts | WordPress's own files. You can dequeue most of them. | content_for_header is Shopify's. Its docs say not to change it, and you can't defer it. |
| The checkout | Yours: WooCommerce's pages, on your server. | Shopify's. Deeper changes need extensions, and some need Shopify Plus. |
On Shopify, the theme is all yours. It's written in Liquid, Shopify's template language. Here is the top of a Shopify theme, and a product photo:
<head> {{ 'theme.css' | asset_url | stylesheet_tag }} {{ content_for_header }}</head> {{ product | image_url: width: 800 | image_tag: sizes: '(max-width: 600px) 100vw, 600px' }}- Line 2 is the theme's own CSS.
asset_urlserves it from Shopify's CDN. - Line 3 is
content_for_header. Shopify's docs say it "Dynamically returns all scripts required by Shopify", and that you "shouldn't try to modify or parse" it. You can't defer it either. Shopify sends the head in two parts, and everything above this tag comes first. So its docs say to put the CSS the first paint needs above it, as line 2 does. - Line 6 asks for the photo 800 px wide with
image_url. Thenimage_tagwrites the img tag, with srcset, width and height. Shopify picks WebP or AVIF for browsers that support them.
Shopify measures for you too. Its web performance reports show LCP, INP and CLS, "based on real user data from the past 30 days", at the 75th percentile. On WordPress, you read CrUX, or collect your own.
Working on any platform
- Start with real visits: CrUX, or the platform's own reports.
- Find who added each file: the theme, a plugin, an app, or the platform.
- Remove what you don't use. Limit the rest to the pages that need it.
- Load app scripts with async or defer, or as app blocks.
- Turn on the platform's cache and CDN. Keep carts and checkouts out of the cache.
- Report what you can't change to whoever made it.
Ravi's answer: Shopify would run the parts Kiran had to set up herself. But the apps and the theme would still be his to check, file by file.
Where does each fix live?
Sort each problem by who can fix it:
- Contact Form 7's files on a product page with no form
- A wishlist plugin that almost nobody uses
- A gallery zoom that downloads the full-size photo on every visit
- A Shopify app's script tag that blocks the first paint
- A plugin you need, whose own script is large
- The scripts Shopify puts in content_for_header
- Which CDN serves a Shopify store's files
Sort each problem by who can fix it.
Common mix-ups
- "WordPress is slow." No. The same WordPress painted Kiran's photo at 3,692 ms before her fixes, and at 1,292 ms after. The plugins and the cache made the difference.
- "A plugin only loads where you use it." No. Contact Form 7 loads its files on every page unless you tell it not to. The wishlist brought React to a page with one heart on it.
- "A page cache makes everything fast." No. It answers pages that are the same for everyone. The answer to Add to cart was built by PHP every time.
- "async means the script runs later." No. It means the browser keeps reading while the script downloads. The script runs as soon as it arrives.
- "Uninstalling an app removes all of its code." No. Shopify removes an app's blocks. Code an app pasted into theme files can stay behind.
- "A hosted platform makes every store fast." No. Most Shopify sites pass, but not all: the apps and the theme still decide a lot.
Practice exercises
Answer each one first, then open the hints if you need them.
This uses the Technology Report's numbers for Drupal, another platform, on desktops. What does it print?
// Drupal sites on desktops: [good LCP, measured].
const lcp = [72292, 82712];
console.log(`${((lcp[0] / lcp[1]) * 100).toFixed(1)}%`);87.4%. That's the share of Drupal sites on desktops whose LCP was good for at least 75% of their visits.
This models, in a few lines, a rule WordPress follows when it prints a deferred script. What does it print?
// A model of WordPress's rule, written for this lesson.
const scripts = {
slider: { wants: "defer", neededBy: ["gallery"] },
gallery: { wants: "blocking", neededBy: [] },
};
function printed(name) {
const script = scripts[name];
const blockingDependent = script.neededBy.some((other) => scripts[other].wants === "blocking");
return blockingDependent ? "blocking" : script.wants;
}
console.log(printed("slider"));blocking. A blocking script that needs the slider must find it already run. So WordPress prints the slider as blocking too. WordPress's 6.3 notes describe this rule.
On the async version, when were the review app's stars on the page, in ms after Asha asked for it?
1,480 ms. The page painted first, then the app's script arrived and asked its own server for the reviews. The stars appeared when they came back.
How many kB of CSS, compressed, did the wishlist plugin's files add to the page?
12.8 kB, in four files. All of them left with the plugin.
Open the course's trace of Kiran's page before the fixes in Chrome's DevTools. Which JavaScript file was the biggest download?
The add-to-wishlist index.js, in the plugin's components folder: the button's own code, about 100 kB compressed.
Shopify suggests a size for the JavaScript an app block or app embed block loads. How big, compressed?
10 KB, compressed. Shopify lists it as a suggestion, not a hard limit.
Check your understanding
For each question, ask two things: who added this, and who can change it?
Question 1 of 7Why did Contact Form 7's files load on the Mint tea page, which has no form?
Choose an answer to see the explanation.
Question 2 of 7A script tag is pasted at the top of the head, with no async and no defer. What does the browser do when it reaches it?
Choose an answer to see the explanation.
Question 3 of 7In the course's recording, what did the page cache not speed up?
Choose an answer to see the explanation.
Question 4 of 7What does line 9 of the cache-rule example print?
Read the code, then predict// May the page cache answer this request? function fromCache(request) { if (request.method !== "GET") return false; return !request.cookies.includes("woocommerce_items_in_cart"); } console.log(fromCache({ method: "GET", cookies: "" })); console.log(fromCache({ method: "POST", cookies: "" })); console.log(fromCache({ method: "GET", cookies: "woocommerce_items_in_cart=1" }));Choose an answer to see the explanation.
Question 5 of 7In HTTP Archive's Technology Report, when does a platform's site count as passing the Core Web Vitals?
Choose an answer to see the explanation.
Question 6 of 7On Shopify, which of these does Shopify manage, not the store owner?
Choose an answer to see the explanation.
Question 7 of 7A Shopify app moves from the ScriptTag API to an app embed block. What changes for the store?
Choose an answer to see the explanation.
Key takeaways
- On a platform, most of the page is other people's code. Find who asked for each file before you change anything.
- A plugin can load its files on every page. Remove what you don't use, and limit the rest to the pages that need it.
- A script pasted at the top of the head blocks the first paint. Load app scripts with async or defer, or as app blocks.
- A page cache skips PHP for pages that are the same for everyone. Carts and checkouts are still built every time.
- Shopify runs the server, the cache and the CDN for you. On WordPress, you choose them yourself.
- Field data per platform is an average. Your own site's numbers come from your own choices.
Remember the one-liner.
On a platform, you rarely write the code: you choose what runs on the page, and who answers it.
Looking back at Stage 11
This lesson ends the stage on architecture and frameworks. Each lesson asked where the work happens, and when:
- Rendering strategies: client, server, static, and islands, by their metrics.
- Streaming: send the page in pieces, so slow data doesn't hold back the rest.
- Hydration: how much JavaScript wakes the page up, and when.
- The edge: running near the visitor helps only when the data is near too.
- Frameworks: React, Next.js, Angular, Vue, Svelte, Astro and Qwik, each with its own tools.
- Platforms: when you didn't write the code, choose what runs and who answers.
Sources
The facts on this page come from these docs, source files and datasets:
- WordPress Playground: Playground CLI, WordPress.
- wp_enqueue_script(), WordPress code reference.
- Loading JavaScript and stylesheet only when it is necessary, Contact Form 7.
- Image performance enhancements in WordPress 6.3, Make WordPress Core.
- Responsive images in WordPress 4.4, Make WordPress Core.
- Registering scripts with async and defer attributes in WordPress 6.3, Make WordPress Core.
- Block styles loading enhancements in WordPress 5.8, Make WordPress Core.
- WordPress 6.9 frontend performance field guide, Make WordPress Core.
- class-wc-frontend-scripts.php, WooCommerce 11.3.0, WooCommerce source.
- Theme app extensions: configuration, Shopify.
- Theme app extensions: UX guidelines, Shopify.
- Defer non-critical resources, Shopify.
- Online store apps: script tags, Shopify.
- Built for Shopify requirements, Shopify.
- WordPress optimization: caching, WordPress.
- class-wp-site-health.php, WordPress 7.1.4, WordPress source.
- Configuring caching plugins, WooCommerce.
- The Shopify platform, Shopify.
- Speculative loading in 6.8, Make WordPress Core.
- speculative-loading.php, WordPress 7.1.4, WordPress source.
- Technology Report API, HTTP Archive.
- tech_crux.js: how the Technology Report counts a passing site, HTTP Archive.
- content_for_header, Shopify Liquid reference.
- image_tag, Shopify Liquid reference.
- Web performance reports, Shopify Help Center.
Coming next: Testing on low-end devices, the first lesson of Stage 12. Real phones, remote debugging and thermal throttling: see your site the way most people do.