Strip filter not working on Capture string

4 0 1

I am trying to strip all empty spaces / tabs / newlines from a "Captured" string but the code below doesn't work when I use the | strip filter. If I use the 'strip_newlines' filter it removes new lines though.


Does anyone no a way to minify this html?


{%- capture styles -%}
   .sidebar li .color-swatch {
      border-radius:{% if block.settings.shape == 'swatches_square' %} 2px {% else %} 50% {% endif %};
   .stacked.label {
      line-height: {{size}}px;
{%- endcapture -%
{{ styles | strip }}
Shopify Expert
553 39 116

strip removes spaces from the start and end of the string.


If you strip all the spaces from that CSS snippet, you'll break that first CSS rule.


To minify CSS, you can add your custom CSS to an Asset and name it like this: custom.scss.liquid.


When it's SCSS and liquid, Shopify will automatically minify it on the server.



Founder of Speed Boostr (Shopify optimization and dev agency).
Creator of Theme Scientist (A/B testing app).
Creator of Order Automator (app that auto tags + fulfills orders, send emails).
Creator of Shopify Analyzer (free performance analysis tool).
I also build custom apps and automated solutions.
Enjoy the adventure!