Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress HTML with Node, Express & EJS?

I'm using EJS with Node and Express. The HTML produced by my views is large and full of unnecessary whitespace. Is there an option or middleware I can use in production that will compress the HTML?

E.g.,

<!doctype html>
<html><head><title>...</title>....</html>
like image 966
a paid nerd Avatar asked Nov 14 '22 06:11

a paid nerd


1 Answers

Your template engine should have a flag that you pass to it to compress it, I know that Jade does it by default (I haven't used EJS).

But I wouldn't bother with whitespace removal, instead I'd use a gzip library to gzip the response down, something like gzippo is what you're after.

like image 181
Aaron Powell Avatar answered Nov 16 '22 16:11

Aaron Powell