Output strings with echo instead of append and prepend
Use the echo tag or {{ }} output tags for string concatenation instead of filters like append or prepend.
Each Liquid filter adds a small amount of processing overhead. For simple string concatenation, direct output avoids this overhead entirely and reduces server-side Liquid execution time.
This is a micro-optimization. In isolation, the difference per call is minimal. In complex themes, these calls accumulate. A product card snippet that uses append five times, rendered 50 times in a collection loop, means 250 filter calls that could be zero. The overhead compounds in the same way that other loop optimizations do: small per-iteration savings multiplied across many iterations add up to measurable TTFB improvements.
Use direct output instead of filter-based concatenation:
When you need the result stored in a variable for later use, assign with append is appropriate. The optimization applies when you're building a string only to output it immediately.
The echo tag outputs a value the same way {{ }} does. It works anywhere in a template, and it's the only way to output a value inside a {% liquid %} block, where {{ }} isn't available:
Anchor to ExamplesExamples
Anchor to Building CSS classesBuilding CSS classes
A common pattern in theme snippets is building a CSS class string:
Anchor to Constructing URLsConstructing URLs
Anchor to Assembling structured data inside a loopAssembling structured data inside a loop
When building structured data (JSON-LD) for product cards in a collection loop, direct output avoids filter overhead on every iteration.
Be careful with filter order when you build JSON with append. In '"price": "' | append: product.price | money_without_currency, the money filter applies to the whole concatenated string, not to the price: the string parses as 0.0 and the block silently renders 0.00.
Don't use money_without_currency for a schema.org price either. It formats using the store's currency settings, so locales with a comma decimal separator produce an invalid price value. Output a plain decimal instead:
Anchor to When filters are still the right choiceWhen filters are still the right choice
Filters are appropriate when you need the result in a variable for reuse, or when the transformation is complex:
Anchor to TestingTesting
- Use the Theme Inspector Chrome extension to measure the impact on Liquid rendering time. Look at per-snippet timing in the flame graph.
- Compare TTFB in the Chrome DevTools Network panel before and after applying this pattern. Filter to the document request and check Waiting for server response.
- The impact is most visible on collection pages and other pages where product card snippets render many times.
Anchor to ReferencesReferences
echotagappendfilterprependfilterassigntagliquidtagdivided_byfiltercapturetag- Debugging common causes for slow loading in Shopify Liquid storefronts
- Avoid deeply nested Liquid loops
- Move operations outside loops