I want to use html-minifier
to minify my html files.
I have install it by npm install -g html-minifier
However, sudo html-minifier rb.html --removeComments
did NOT remove the comments in rb.html
.
Does anyone know how to use it?
Additionally, I just want to minify the size of the html files by keeping exactly the same layout, what are conventional parameters that we put to html-minifier
?
To minify HTML, try HTMLMinifier. To minify CSS, try CSSNano and csso. To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective.
If you want faster page load times and better performance scores, you will want to minify you HTML, CSS and Javascript files. With all the online tools available, you can easily minify your code for any website.
Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.
You can target all html files in a specified directory with the following command:
html-minifier --input-dir dist --output-dir dist
With this example script I am compressing all html files in dist and outputting them to the same directory — essentially replacing the uncompressed html files with the compressed ones.
The command above actually doesn't do anything to the files because no options were defined. Some useful options are:
--collapse-whitespace
: Collapse whitespace that contributes to text nodes in a document tree.--remove-comments
: Remove HTML comments--minify-css
: Minifies embedded and inline CSS (<style></style>
and style=""
)--minify-js
: Minifies embedded and inline JS (<script></script>
and e.g onload=""
)Here's a command that you may end up with:
html-minifier --input-dir dist --output-dir dist --remove-comments --collapse-whitespace --minify-js --minify-css
To see the complete list of available options, run html-minifier -h
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With