How to batch minify HTML pages in linux command line

First, install a nodejs module:

1
npm install html-minifier-cli -g

Second, write a script like this:

1
2
3
4
5
6
cd public
for f in $(find . -name '*.html'); do
echo "Minifying $f ..."
htmlmin -o $f.min $f
mv $f.min $f
done
Share