Shopify Liquid Memory Limit Error: Fixes
April 4, 2026If you’ve ever seen the message
Liquid error: Memory limit exceededAs an expert Shopify consultant, I see this frequently in stores that have grown rapidly or have inherited complex, poorly optimized themes. Here’s how to diagnose and fix it before it costs you conversions.
What causes this error?
The error occurs when the Liquid execution engine reaches its allocated memory limit while rendering a single page. This limit is generous but finite. The most common causes are:
- Massive loops: Iterating over thousands of products or blog posts without pagination.
for - Deeply nested loops: A loop inside a loop inside a loop (e.g., looping through all collections, then all products in each collection, then all variants of each product).
- Inefficient lookups: Repeatedly calling
all_productsinside a loop.all_products['handle'] - Large string manipulations: Concatenating massive amounts of text or building complex JSON objects manually in Liquid.
- Lack of pagination: Attempting to display more than 50 products on a single collection page without using the tag.
paginate
Diagnosis: Finding the Bottleneck
The first step is identifying which part of your code is the culprit.
- Check Recently Added Sections: Did the error start after adding a "Related Products" section or a custom "Mega Menu"?
- Audit Collection Pages: Look for any logic that bypasses pagination or uses .
all_products - Use Shopify’s Theme Inspector: The Chrome Extension "Shopify Theme Inspector for Chrome" is your best friend. It shows you exactly which parts of your Liquid code are taking the most time and memory to render.
Pro-Active Fixes
1. Always Use Pagination
Shopify limits you to 50 products per page for a reason. If you need to show more, you must use the
paginatecollections.all.products{% paginate collection.products by 48 %} {% for product in collection.products %} <!-- Render product --> {% endfor %} {{ paginate | default_pagination }} {% endpaginate %}
2. Avoid Nested Loops Like the Plague
If you have to loop through all collections and then all products, you are likely doing it wrong. Instead, consider using tags or a dedicated "all-products" collection to filter what you need.
The Bad Way:
{% for collection in collections %} {% for product in collection.products %} <!-- This will crash your store if you have many collections/products --> {% endfor %} {% endfor %}
The Good Way: Use AJAX or the Search API. If you need complex filtering, consider an external search tool or building a custom app that indexes your products in a way that’s easier to query.
3. Stop Using all_products
Inside Loops
all_productsEach call to
all_productsall_productsInstead, use a linklist or a collection to group related products, which is much more memory-efficient.
4. Offload to JavaScript
If you need to perform complex calculations or data transformations, don't do them in Liquid. Render the raw data into a JSON object or a set of data attributes, and then use JavaScript on the client side to handle the heavy lifting.
<script id="product-data" type="application/json"> {{ collection.products | json }} </script>
Liquid is a templating engine, not a full-featured programming language. Let it handle the structure and let JavaScript handle the interactivity.
5. Cache with Caution
While Shopify does some caching, you can't manually cache Liquid outputs. However, you can use the
renderincluderenderSummary: Keep it Lean
The
Memory limit exceededIf your Shopify Plus store is hitting these limits and you need an expert to refactor your theme for high-scale performance, get in touch. I specialize in making Shopify stores lightning-fast for the South African market.