The original poster seeks a way to minify a styles.css.liquid file without using Shopify’s deprecated Sass processing. Traditional CSS minifiers fail because they don’t correctly handle Liquid template tags embedded in the CSS.
Solution Provided:
A community member shared a Liquid-based minification workaround that wraps the CSS file contents in a {%- capture content %} block. The code:
Removes comments, extra spaces, and newlines
Preserves Liquid tags during minification
Runs at runtime rather than build time
Works sufficiently for Google PageSpeed/Lighthouse metrics
Implementation:
Place the minification code directly in the css.liquid file, wrapping it around existing CSS+Liquid statements. The capture block goes at the start, with processing logic at the end to output the minified result.
Follow-up Questions:
Several users requested clarification on exact placement within theme files (whether in theme.css.liquid, inside <body> tags, or elsewhere). The thread remains open with implementation details being discussed.
Summarized with AI on November 18.
AI used: claude-sonnet-4-5-20250929.
My goal here to is to minify the rather bloated styles.css.liquid in my theme.
Googling suggests the best way to do this is make sure the css file saved as a sass file so Shopify will process and minify if for you. However Shopify has deprecated sass: https://www.shopify.com.au/partners/blog/deprecating-sass
Has anyone found a CLI tool that I can add into my CI/CD pipeline that can minify a css file containing liquid tags? I’ve tried uglifycss and it fails with blocks like this:
Thanks, that works well. Seems a bit strange to have to do it at runtime when I have a static build process for the theme but it worked well. Appreciate the response.