Skip to content

Instantly share code, notes, and snippets.

@sskylar
Last active January 8, 2021 19:00
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sskylar/7557528 to your computer and use it in GitHub Desktop.
Save sskylar/7557528 to your computer and use it in GitHub Desktop.
Simple HTML minify with Liquid/Siteleaf. Strips all line breaks, tabs, and extra spaces.
{% capture html %}
<html>
...
</html>
{% endcapture %}{{ html | strip_newlines | replace:' ','' | replace:' ','' | replace:' ',' ' }}
@mattmischuk
Copy link

@agriboz whoa, a blast from the past. Now that prettier is a thing I don't really concern myself with these types of problems. Since 2015 there are many good html parsers and I wouldn’t recommend relying on liquid to do anything of the sort.

https://github.com/ikatyang/angular-html-parser/tree/master/packages/angular-html-parser

I say, move nonsense like this to a build step. Also, minifying HTML isn't really a big deal. I mean if you’re nutty about perf you’ll likely need to invest some time into learning how to minify HTML with a webpack, rollup, gulp task (or whatever Ruby alternative).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment