PageSpeed Puzzle: Why Your Shopify Store's Scores Might Be Inconsistent (and What `content_for_header` Has to Do With It)

Hey everyone! As someone who spends a lot of time digging into Shopify store performance and chatting with store owners like you, I know firsthand how frustrating it can be to see your PageSpeed Insights scores jump all over the place. One minute you're in the green, the next you've taken a nosedive, even without making any changes to your site. It feels like a mystery, right? Well, a super sharp community member, Naveed from Resin Rock, has been doing some incredible detective work, and he's uncovered something really interesting that might explain these wild swings.

The PageSpeed Rollercoaster: What's Going On?

Naveed initially brought up a perplexing issue: his live Shopify store, even after a thorough cleanup, was showing wildly inconsistent PageSpeed scores. On some runs, it would score a respectable 91-95. On others, for the exact same page tested minutes apart, it would plummet to 63-68. The kicker? His real-user data (what Google calls CrUX, or Chrome User Experience Report) was consistently green. This immediately told us something important: the issue wasn't necessarily affecting actual visitors, but rather Google's PageSpeed Insights testing environment, specifically Lighthouse (which PageSpeed Insights uses).

He observed a very specific problem: a delay of 1.1 to 2.2 seconds before the first visual content "paints" on the screen in Lighthouse tests. This wasn't network noise; these specific delay values suggested a timeout mechanism at play. Imagine your browser receiving all the HTML, finishing all render-blocking resources, and even firing DOMContentLoaded and load events – but the screen just stays blank for another couple of seconds. That's exactly what Naveed was seeing.

The Suspect: Shopify's content_for_header

After extensive testing and ruling out common culprits, Naveed narrowed down the problem to something called content_for_header. If you're not a developer, you might not be familiar with this, but it's a crucial part of every Shopify theme. It's where Shopify automatically injects a lot of essential code into the section of your store's HTML – things like scripts for apps, analytics (like trekkie), and other core Shopify functionalities. Think of it as a central hub for all the behind-the-scenes magic that makes your store run.

Naveed set up a brilliant, reproducible test case with two identical pages on his store:

  • Page A: Included the theme stylesheet and content, but intentionally omitted content_for_header.
  • Page B: Identical to Page A, but included content_for_header.

He ran these pages repeatedly through pagespeed.web.dev (using a cache-busting query parameter like ?r=). The results were stark: Page A consistently painted within ~0.1 seconds. Page B, however, painted fast on some runs and then inexplicably held back by 1.1-2.2 seconds on roughly a third to a half of the runs. This strongly suggested that something within the code injected by content_for_header was the trigger.

What Was Ruled Out?

Naveed's investigation was thorough. He meticulously ruled out many factors that could typically cause such delays, including:

  • Theme CSS, fonts, images, and JavaScript (Page A carried these and never held).
  • The shop.app cart-sync iframe (blocking it didn't remove the hold).
  • Even blocking all iframes with a CSP frame-src 'none' only roughly halved the hold rate, it didn't eliminate it.
  • Painting the first element earlier or starting theme scripts later also made no difference.

This pointed to a deeper, more fundamental issue related to how Lighthouse interacts with Shopify's injected code.

Why This Matters for Your Store (and Your Sanity)

The core problem here is how Lighthouse calculates metrics like First Contentful Paint (FCP) and Largest Contentful Paint (LCP). If Lighthouse perceives a 1-2 second delay before the first visual paint, it drags all the loading time of your apps and resources into those crucial metrics. This means a perfectly optimized store could suddenly look "slow" to PageSpeed Insights, even when real users are having a great experience.

This discrepancy leads to a lot of confusion and frustration for store owners. You might spend hours optimizing your store, only to see wildly inconsistent scores that don't seem to reflect your efforts or your customer's actual experience. Naveed even found this same hold on major Shopify stores like Allbirds, Gymshark, and Fashion Nova, indicating it's a widespread platform issue, not just an isolated case.

What's Being Done?

Naveed did the right thing and escalated this. He filed an issue with Lighthouse directly (Lighthouse issue #17230) and also posted it on the Shopify developer forum. Shopify Support, in this specific instance, indicated that content_for_header was outside their direct scope for front-line support, which is why bringing it to the developer community and Lighthouse team was the correct next step.

This is a complex issue that requires collaboration between Shopify's performance team and the Google Lighthouse team to fully understand and resolve. It seems to involve how Chrome (specifically in the Lighthouse testing environment) handles "frames being held back" – a behavior noted in Chrome's own metrics changelog for version 111 and above.

What You Can Do (and What You Should Know)

For now, direct action for store owners is limited, as this appears to be a platform-level interaction issue. However, awareness is key!

  1. Understand the Discrepancy: If your PageSpeed scores are erratic but your real-user data (CrUX, or other analytics like Google Analytics showing good bounce rates and time on site) is solid, you might be encountering this exact issue.
  2. Focus on Real User Experience: While PageSpeed Insights is a valuable tool, remember that real user experience (what your actual customers see) is paramount. Don't get overly fixated on a fluctuating PageSpeed score if your CrUX data is green.
  3. Stay Informed: Keep an eye on the Shopify developer community and Lighthouse GitHub issues. Solutions or workarounds for this kind of platform-level bug often emerge there first.

It's a testament to the power of the Shopify community that dedicated individuals like Naveed are diving deep into these technical challenges. This kind of detailed investigation helps everyone, pushing both Shopify and Google to refine their tools and platforms for a better experience for all merchants. Hopefully, with this visibility, a fix or a clearer understanding of this "held frame" issue will be coming our way soon!

Share:

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases