Rails erb html minification

158 views
Skip to first unread message

Roman Usherenko

unread,
Jun 6, 2016, 5:49:53 AM6/6/16
to Guardians of the Temple
Hi!

Anyone knows a nice way to minify HTML output of erb templates in Rails? Right now I use a middleware that gsubs "\n"'s between close and open tags, but this happens on each page load and depending on a page size can be taxing on performance.

I'm looking to write some kind of a template engine (based on, or compositing Erubis), that will tap into Rails template handlers chain so that the compiled result will be cached by rails. Ideally I also do not want to change all my template files extension from *.erb to something else.

Any advises?

Magnus Holm

unread,
Jun 6, 2016, 5:55:35 AM6/6/16
to guardians-o...@googlegroups.com
Hi Roman,

I don't know of any HTML-aware ERB-templates. Slim/Haml handles HTML in its syntax, and thus have way more control over what it generates. How HTML-aware do you want the template engine to be? Should it also catch invalid HTML?

I also don't know how to hook into Rails' template engine. But that's easy to figure out.


// Magnus Holm

--
You received this message because you are subscribed to the Google Groups "Guardians of the Temple" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guardians-of-the-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages