Notes · Oleksandr Osadchyi · Updated · 6 min read

Magento 2 PageSpeed with Fastly: what to fix first

Your Magento 2 store has Fastly and Varnish, and PageSpeed Insights still says 46 on mobile. The CDN delivers the HTML fast. The score is lost in the browser. This is a store I worked on this month: Adobe Commerce 2.4.8, Fastly, about 25,000 products, mobile score 46, LCP 9.2 s, TBT 1,150 ms. Below is what was slow and the order to fix it in.

I am Oleksandr Osadchyi, an ex-Magento 2 core engineer and Adobe Certified Master, Adobe Commerce Architect, with 13 years on Magento stores. My commits are in the public magento/magento2 repository.

What Fastly fixes and what it leaves

Fastly is a Varnish-based service that caches pages, assets and CSS. On this store the first paint (FCP) came at 1.9 s, which is fine.

Everything after the HTML arrives happens on the phone. Lighthouse reports render-blocking stylesheets, third-party scripts and DOM size as separate problems, and a cache does not touch any of them. Here the main thread was busy for 6.6 s, and 3.8 s of that was script evaluation. Google counts LCP as good up to 2.5 s and poor above 4 s.

Why local Lighthouse says 72 to 89 and PageSpeed says 46

Lighthouse on my machine gave the same page 72 to 89. Both tools run Lighthouse. The difference is the CPU. Lighthouse slows the processor by a multiplier, 4x by default, and that multiplier is relative to the machine that runs the test. A fast laptop slowed 4x is still much faster than the mid-tier phone PageSpeed simulates.

The report shows the machine's benchmark index at the bottom. Mine is about 4,100. The Lighthouse docs put a high-end desktop at 1,500 to 2,000. I raised the multiplier to 12x, which is my own calibration, and the score was still 72.

So do not compare a local score with the PageSpeed score. Use local runs to check that a cause is gone, and PageSpeed on the same URL for the number.

What was slow

CauseCostWhere it comes from
Render-blocking CSS10 files, the main one 80 KB, about 650 msTheme
Hero image with no priority1920×900 sent to a 412 px phone. It is the LCP elementCMS banner
reCAPTCHA on every pageAbout 0.8 s CPU, 1.2 MBThe login form is on every page
Monitoring (RUM) agent81 KB inline in <head>Injected on the server by New Relic
Google Tag ManagerAbout 0.5 s CPUAnalytics tags
jQueryAbout 0.6 s CPUClassic Luma-type frontend
Mega-menu79 KB of a 209 KB document, about 1,650 DOM elementsMenu HTML on every page
Unused JavaScriptAbout 880 KBTheme and extensions

For scale: Lighthouse warns at about 800 DOM nodes and reports an error at about 1,400.

The fix order

The order is by effect against risk. Each step is measured on staging with the same settings before the next one starts.

FixEffectRiskWho decides
A. Hero image: high priority, phone-sized sourceLarge LCP gainLowDeveloper
B. Critical CSS inline, the rest asyncAbout 650 ms of blocking removedMedium: critical.css must be accurateDeveloper
C. reCAPTCHA loads on form interaction0.3 to 0.8 s less blocking on every pageMedium: form validationDeveloper, with the owner
D. Lighter monitoring agent, or none on the storefrontUp to 81 KB out of <head>Less browser dataStore owner
E. Tag Manager after page loadAbout 0.5 s CPU moved out of the loadTags fire laterAnalytics owner
F. Unused JavaScript cleanupPart of 880 KBHigher effortDeveloper
G. Lazy mega-menuSmaller HTML and DOMHigher effortDeveloper

A. The hero image

Three rules from web.dev:

<img src="hero-1920.jpg"
     srcset="hero-480.jpg 480w, hero-960.jpg 960w, hero-1920.jpg 1920w"
     sizes="100vw" width="1920" height="900"
     fetchpriority="high" alt="...">

Fastly Image Optimization will not make the small files for you here. Adobe's page says it resizes product images only: "CMS images are not resized". A hero banner is usually a CMS image, so the phone sizes have to be created and referenced in the banner.

B. Critical CSS

Magento has had this built in since 2.3.3, and it is off by default. The setting is dev/css/use_css_critical_path. With it on, the contents of critical.css go inline in <head> and every other stylesheet loads without blocking the render. The Developer tab is hidden in production mode, so set it from the command line:

bin/magento config:set dev/css/use_css_critical_path 1
bin/magento cache:flush

On Adobe Commerce Cloud add --lock-config, commit app/etc/config.php and redeploy.

The file lives at app/design/frontend/<Vendor>/<theme>/web/css/critical.css. If your theme has none, Magento uses Luma's file, which was written for Luma's layout. A custom theme needs its own. Adobe's rules for the file:

On the other CSS and JS settings: set Minify CSS, JS and HTML to Yes. Adobe's playbook says "Do not merge or bundle files if your deployment uses HTTP/2."

C. reCAPTCHA on interaction

Magento turns reCAPTCHA on per form under Stores > Settings > Configuration > Security > Google reCAPTCHA Storefront. When the protected login form sits in the header, the script loads on every page. I found no core setting that delays it, so this is a small custom change: load api.js when the visitor first touches a form.

It is a trade-off. Google's v3 docs say reCAPTCHA "works best when it has the most context about interactions with your site" and recommend it in the background of pages. Loading it late gives the score less context. Test every protected form after the change.

D and E. Decisions for the owner

The New Relic PHP agent injects the browser script by default, so it is not in your repository. There are two options:

Tag Manager can load after the main content. The tags then fire later, so the person who owns analytics has to agree to it.

Results

Results after steps A to C will be added here.

How I do this for stores

You give me a staging copy. I run the audit and return a list like the one above: each cause, its cost, the fix, the risk and who decides. Then I do the fixes one at a time and measure each on staging with the same settings, so you see what every step gave.

I was a Magento 2 core engineer, so the fixes use what the platform already has before any new extension. My workflow is Claude Code for the writing and my own review of every line. I bill by the hour and you pay only for hours worked. My rate is on the pricing page.

FAQ

Why is my PageSpeed score low when I have Fastly?

Fastly speeds up delivery of the HTML and the files. The score also counts what the phone does after that: CSS that blocks the render, scripts and a large DOM.

Why does my developer's Lighthouse show a higher score?

Lighthouse throttles the CPU relative to the machine it runs on. A fast laptop gives a higher score at the same setting.

Should I turn on merging and bundling?

Minify, yes. Adobe advises against merging and bundling when the store is served over HTTP/2, and says built-in bundling is not recommended where the first page load is critical.

Will a Magento upgrade fix the score?

Not in this case. The store was already on 2.4.8, a release with standard support until May 31, 2028. Every cause in the table was in the theme, the content or a third-party script.