Revolutionize Your Business Consultant Operations

Pages / Shopify / Reducing Time to First Byte (TTFB) on Shopify

Simply the best approach for your company we Ask and questions

If you are experiencing slow server response times, standard caching advice will not work because you do not have access to Shopify’s backend infrastructure. To effectively reduce TTFB, Shopify store owners must optimize Liquid architecture. (If you need a refresher on the network mechanics behind this metric, read our guide on How to Fix High Time to First Byte (TTFB)). Below is the advanced workflow for resolving backend latency.

This document provides a technical guide on how to reduce Time to First Byte (TTFB) on Shopify, focusing on backend latency issues that impact storefront performance. It explains that frontend optimizations are ineffective against server-side bottlenecks and that solutions lie within Liquid architecture, app integrations, and caching.

 

Why You Need to Reduce TTFB: Shopify Symptoms

Backend latency is identified by focusing on the initial document request rather than frontend metrics like LCP.

The "White Screen Hang"

  • Users experience a blank screen with a loading spinner for 500 milliseconds to over two seconds before any visual elements appear.
  • During this time, the browser waits for Shopify servers to compile Liquid code, query the database, and return the initial HTML document.
  • This delay prevents the browser from downloading critical assets, negatively impacting user experience and increasing bounce rates.

Wait-to-Download Disparity in Chrome DevTools

  • In Chrome DevTools Network tab, a healthy server response shows a short “Waiting (TTFB)” metric followed by “Content Download.”
  • A problematic Shopify store exhibits a significantly longer “Waiting (TTFB)” bar compared to the “Content Download” bar.
  • This disparity indicates that Liquid code is delaying the server response, not the user’s internet connection or HTML file size.

Root Causes of High Shopify TTFB

Shopify’s hosted SaaS nature means latency is determined by the efficiency of theme code in requesting and processing data.

Inefficient Liquid Nested Loops

Wrapping variant or metafield lookups within collection-level loops creates an exponential processing load. Example: Looping through 50 products, then 10 variants and 5 metafields for each, results in thousands of individual queries. Shopify limits server execution time per page request; excessive iterative processing leads to throttling or delays.

Legacy Scope Inheritance ({% include %})

The deprecated {% include %} tag in older or modified themes causes Liquid to inherit the entire parent scope of variables. This forces the engine to track and pass unnecessary variables in memory across multiple files, leading to a massive server-side memory leak as components are nested.

App-Induced Server-Side Bloat

Third-party apps can inject leftover Liquid “legacy” code into theme.liquid, which the server attempts to execute on every page load even after app uninstallation. “App Proxies” cause “double-hop” latency: Shopify pauses rendering, requests data from an external third-party server, waits for its response, and then injects the data.

Cache-Bypassing Logic

Certain Liquid logic, such as customer-specific checks (if customer) or cart-dependent logic wrapping entire sections, bypasses the cache. This forces dynamic, slow server-side generation for each user, negating the CDN’s advantage.

Failed Fixes (Common Misunderstandings)

Misaligned Frontend Optimization

Optimizing frontend assets like images (WebP, lazy-loading) or scripts (minifying JS/CSS) improves frontend metrics (LCP, FCP) but has no impact on backend latency. Server response time occurs before the browser processes these assets.

Third-Party CDN Layering

Adding a third-party CDN (e.g., Cloudflare, Fastly) in front of Shopify adds unnecessary DNS routing and SSL handshake latency. A third-party CDN cannot speed up Liquid code execution on Shopify’s origin servers.

Solutions to Reduce Server Response Times

High-Performance Liquid Refactoring

Migrate from {% include %} to {% render %}:

// Inefficient Legacy Approach
{% for product in collection.products %}
  {% include 'product-card' %}
{% endfor %}

// Optimized Render Approach
{% for product in collection.products %}
  {% render 'product-card', product: product %}
{% endfor %}
    

Eliminate manual nested for-loops:

// Slow Nested Loop
{% assign available_variants = "" %}
{% for variant in product.variants %}
  {% if variant.available %}
    {% assign available_variants = available_variants | append: variant.id | append: "," %}
  {% endif %}
{% endfor %}

// High-Performance Filter Approach
{% assign available_variants = product.variants | where: "available", true | map: "id" | join: "," %}
    

Asynchronous Rendering (Section Rendering API)

Use the Section Rendering API to deliver a heavily cached, static version of the page instantly, minimizing TTFB. Asynchronous JavaScript (AJAX) then fetches specific dynamic blocks (e.g., cart count) and injects them into the DOM after the initial cached HTML loads.

Edge Frameworks (Hydrogen & Oxygen)

For extreme personalization, migrate to a headless architecture using Shopify’s Hydrogen framework. Hydrogen uses React Server Components to execute rendering logic at the edge, closer to the user, bypassing the central Ruby infrastructure. This enables sub-100ms response times globally.

Frequently Asked Questions

Can I change my server location to be closer to my customers?

No, you cannot manually change your server location. Shopify uses a Global Anycast Network and their own CDN to serve your site from the data center closest to the user automatically. If your TTFB is high, it’s almost never a “location” issue; it’s usually a processing delay caused by your Liquid code or installed apps before the page is even sent.

Should I put Cloudflare in front of Shopify to fix TTFB?

Generally, no. Shopify already uses Cloudflare (and other CDNs) at the platform level. Adding a second layer of Cloudflare can actually increase TTFB because it adds an extra “hop” for the data to travel through. It can also interfere with Shopify’s native SSL certificates and automatic image optimization. Only use an external CDN if you have a very specific enterprise-level use case.

How do I find out if an App is ruining my server response time?

You can use the Shopify Theme Inspector for Chrome. This tool provides a flame graph that shows exactly which Liquid files are taking the longest to render. If you see a specific app’s snippet (e.g., {% include 'app-product-reviews' %}) taking 500ms to load, that app is directly inflating your TTFB

Let's Start Building a System That Holds Up