Cracking the Code: The Shopify Head Code Delay Mystery & Your PageSpeed Scores

Ever felt like Google PageSpeed Insights is playing tricks on you? One minute your store scores a stellar 90+, the next it's dipping into the 60s, all without you changing a thing. It's frustrating, right? You work hard to optimize your store, only to see these wild fluctuations, making you doubt if your efforts are even making a difference.

Well, you're not alone. This exact scenario sparked a really important discussion in the Shopify community forums, led by a sharp mind named Naveed.Shopify. He uncovered a fascinating, somewhat baffling, issue that seems to be affecting many Shopify stores, causing inconsistent PageSpeed Insights results. Let's dive into what he found and what it means for your store.

The Mystery of the Blank Screen Delay

Naveed noticed that his client's live Shopify store, even after a thorough cleanup (it had 29 apps!), was experiencing this bimodal scoring pattern: some runs would score high (91-95), while others would be significantly lower (63-68). The puzzling part? These scores were for the exact same page, run minutes apart. What was even more intriguing was that the store's real-user performance data (CrUX) was consistently green, meaning actual visitors weren't experiencing these slowdowns.

He dug deeper and found that on these "held" runs, the screen would stay completely blank for an extra 1.1 to 2.2 seconds after the HTML had already arrived and all render-blocking resources had finished loading. Even critical events like DOMContentLoaded and load were firing during this blank period! It was like the browser was just sitting there, waiting for something before it decided to paint the page. Crucially, he couldn't reproduce this delay on a local Chrome browser; it only happened when tested by Google's PageSpeed Insights (specifically, the Lighthouse/Lightrider engine).

The Culprit: Shopify's content_for_header Code

After extensive testing, Naveed narrowed down the cause to something called content_for_header. This is a special Liquid tag in Shopify themes where the platform injects various essential scripts and styles – things like analytics loaders (trekkie), pixel managers, and compatibility CSS (like accelerated-checkout-backwards-compat.css). It's core Shopify platform code, not something you as a merchant directly control or add.

He created a brilliant reproduction case: two identical pages on his test store, "Page A" and "Page B".

  • Page A: Included the theme stylesheet and content, but omitted content_for_header. This page consistently painted within ~0.1 seconds of HTML arrival on every PageSpeed Insights run.
  • Page B: Was identical to Page A, but included content_for_header. This page would paint quickly on some runs, but on roughly a third to a half of runs, it would experience the dreaded 1.1 or 2.2-second delay.

These stable 1.1-second and 2.2-second delay values strongly suggest a timeout mechanism rather than random network noise. What's more, Naveed found this isn't isolated to just his client's store; he observed the same hold-up on major Shopify stores like Allbirds, Gymshark, and Fashion Nova! This confirms it's a widespread, platform-level issue.

Why This Matters for Your PageSpeed Scores

Here's the rub: Lighthouse's simulation, which powers PageSpeed Insights, counts every request that finishes before the "observed first paint" into your First Contentful Paint (FCP) and Largest Contentful Paint (LCP) metrics. So, when this mysterious 1-2 second delay happens, Lighthouse sees all those essential Shopify scripts and app resources loading during that blank period, and it unfairly attributes that entire delay to your FCP/LCP. This can cost affected runs about 30 points, dragging your score from a healthy 90s down to the 60s.

As Naveed pointed out, "Merchants see 61 one minute and 93 the next on an unchanged page, and non-technical merchants read the 61 as their store being slow." This inconsistency is incredibly misleading and frustrating for store owners trying to improve their site's performance.

What Was Ruled Out (It's Not Your Fault!)

To be clear, Naveed's testing showed this isn't typically due to your theme, images, or even most apps directly. He ruled out a lot:

  • Theme assets: Page A, with all theme CSS, fonts, images, and JavaScript, never held back.
  • Shop.app cart-sync iframe: Blocking it didn't remove the hold.
  • All iframes: Blocking all iframes only roughly halved the hold rate, it didn't eliminate it.
  • Early painting/script starts: Trying to paint the first element before any body stylesheet or starting theme scripts only after the first frame made no difference.

This really underscores that the core issue lies within Shopify's injected content_for_header code and its interaction with how Lighthouse measures performance.

What's Being Done About It & What You Can Do

Naveed has done an excellent job bringing this to light. He initially contacted Shopify Support, but they indicated that content_for_header was outside their direct scope. He then posted it to the Shopify developer forum and, crucially, filed it as an issue with Google's Lighthouse project itself (Lighthouse issue #17230). This means the right people at both Shopify and Google are now aware of this specific, reproducible bug.

So, what does this mean for you, the store owner?

  1. Don't Panic About Fluctuating PSI Scores: If you see wildly different scores on PageSpeed Insights for the same page, take a deep breath. Remember that your real-user data (CrUX) is often a more accurate reflection of your customers' experience. If your CrUX data is green, your actual users are likely having a good experience.
  2. Keep Optimizing the Basics: While this specific bug is outside your direct control, don't stop optimizing your store. Continue to compress images, audit your apps, streamline your theme, and follow general best practices. These efforts still contribute significantly to overall speed and user experience.
  3. Stay Informed: Follow discussions in the Shopify community forums or keep an eye on the Lighthouse GitHub issue Naveed filed. The more awareness there is, the more likely a resolution will come.
  4. Advocate (If You Can): If you have a developer or are active in the community, consider lending your voice to these discussions. The more merchants and developers highlight the impact of this bug, the more attention it will receive from Shopify and Google.

Ultimately, this is a complex, platform-level challenge that the community is actively working to address. It highlights the intricate dance between e-commerce platforms and web performance measurement tools. For now, understand that those inconsistent PageSpeed scores might not be a reflection of your store's true speed, but rather a quirk in how a specific piece of Shopify's core code interacts with Lighthouse. Keep focusing on delivering a great experience for your customers, and let's hope for a fix from the core teams soon!

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools