---
title: Liquid performance optimization patterns
description: >-
  A reference of compounding Liquid micro-optimizations that together can save
  25 to 50 ms of TTFB on complex themes.
source_url:
  html: >-
    https://shopify.dev/docs/storefronts/themes/best-practices/performance/liquid-performance-patterns
  md: >-
    https://shopify.dev/docs/storefronts/themes/best-practices/performance/liquid-performance-patterns.md
api_name: liquid
---

# Liquid performance optimization patterns

A guide to micro-optimizations that compound for measurable TTFB improvements on complex themes.

***

## Overview

Individual Liquid micro-optimizations might appear small, but on complex themes they compound significantly. On a theme with 50 sections and multiple blocks per section, applying all patterns together can save 25 to 50 ms of TTFB. Individual patterns save 1 to 5 ms each, but the combined effect becomes noticeable.

Prioritize higher-impact optimizations first. These patterns are most effective on complex themes with many sections, blocks, or nested logic. Use the Theme Inspector Chrome extension to measure the impact on your Liquid rendering time, and compare TTFB in WebPageTest before and after applying these patterns.

***

## Loop optimizations

* **[Move operations outside loops](https://shopify.dev/docs/storefronts/themes/best-practices/performance/move-operations-outside-loops)**: Move operations that produce the same result on every iteration outside the loop.
* **[Avoid excessive conditionals in loops](https://shopify.dev/docs/storefronts/themes/best-practices/performance/avoid-conditionals-in-loops)**: Minimize the number of conditional checks inside loops, especially for complex conditions.

***

## Caching patterns

* **[Assign `block.settings` to a variable](https://shopify.dev/docs/storefronts/themes/best-practices/performance/assign-block-settings-to-variable)**: Assign the `block.settings` object to a variable and reference the variable instead of accessing it repeatedly.
* **[Avoid repetitive filter calls](https://shopify.dev/docs/storefronts/themes/best-practices/performance/avoid-repetitive-filter-calls)**: If you're calling the same filter repeatedly with the same arguments, cache the result.

***

## Data access patterns

* **Filter in Liquid instead of making multiple database calls**: When multiple sections or snippets use the same data but filter it differently, don't restructure the code to make separate database queries for each filtered view. Liquid filtering runs in Rust and is very fast. Making multiple database calls to prefilter data is slower because each call adds network and query overhead. Fetch the data once and filter it in Liquid.

***

## Code structure patterns

* **[Use `echo` for string output](https://shopify.dev/docs/storefronts/themes/best-practices/performance/use-echo-for-concatenation)**: Using the `echo` tag or `{{ }}` output tags is faster than using string manipulation filters.
* **[Avoid nested renders](https://shopify.dev/docs/storefronts/themes/best-practices/performance/avoid-nested-renders)**: Minimize nesting of snippets, especially inside loops.

***

## References

* [Avoid deeply nested Liquid loops](https://shopify.dev/docs/storefronts/themes/best-practices/performance/avoid-deeply-nested-liquid-loops)
* [Optimize metafield access](https://shopify.dev/docs/storefronts/themes/best-practices/performance/move-metafield-access-outside-loops)
* [Reduce mega-menu DOM overhead](https://shopify.dev/docs/storefronts/themes/best-practices/performance/reduce-mega-menu-dom-overhead)

***
