html-webpack-plugin icon indicating copy to clipboard operation
html-webpack-plugin copied to clipboard

Consider using @minify-html

Open wilsonzlin opened this issue 5 years ago • 6 comments

Hello :wave:

I've been working on an HTML minifier that is 10X faster than html-minifier while being more effective. It's written in Rust but is available for Node.js as a package (npm i hyperbuild) using native bindings. It also natively binds to esbuild for very fast JS minification (100X faster than terser).

You can see the project and more details here, which goes into the complex minification strategy. It's super easy to use, has TS typings, and has been extensively tested with fuzzing.

Let me know if there's interest in using this for html-webpack-plugin; I can help integrate or alleviate any issues that arise. Also happy to add overlooked or friendliness features currently missing. Thanks!

wilsonzlin avatar Jul 10 '20 20:07 wilsonzlin

Hey

👋 thanks for your work that looks really promising - downloading a 230 MB is very much to process 5kb text files..

The html-webpack-plugin was downloaded 250.000.000 times last year. That would be 57.500 TerraByte on top if we go for your plugin. Most CI-CDs use caching but there are still a lot of them which will download your package on every run. So if the download takes slightly longer but the processing is slightly faster it might not help much.

I was also wondering why you didn’t give the module a name which is easier to understand on first glance e.g. html-minifier-rust

If I read it correct it has trouble parsing invalid markup would probably break a lot of people’s build which generate templates for e.g. php or jsp

But still - cool work! Right now I would like wait until it becomes a little bit more mature :) I hope you understand that

jantimon avatar Jul 11 '20 09:07 jantimon

Thanks for the reply, and great points :smile:

The html-webpack-plugin was downloaded 250.000.000 times last year. That would be 57.500 TerraByte on top if we go for your plugin. Most CI-CDs use caching but there are still a lot of them which will download your package on every run. So if the download takes slightly longer but the processing is slightly faster it might not help much.

Good point, unfortunately this is due to Neon's lack of support for N-API so far, so builds have to be included for each Node.js version and platform. I will probably revert to using online platform-specific downloads at install time like what esbuild does.

I was also wondering why you didn’t give the module a name which is easier to understand on first glance e.g. html-minifier-rust

Legacy decision, as it started off being a preprocessor as well for HTML files. Will rename once I get it polished.

If I read it correct it has trouble parsing invalid markup would probably break a lot of people’s build which generate templates for e.g. php or jsp

Good point, will look to add this feature; right now it's mostly a pure HTML minifier.

It would be tricky to process <?php blocks, as it seems it would require understanding and parsing PHP syntax, like <?php echo '<?php ?>'; ?>.

But still - cool work! Right now I would like wait until it becomes a little bit more mature :) I hope you understand that

Yeah no worries, it's only on version 0.2 right now :smiley: Will focus more on Node.js ergonomics for the next few versions :+1:

wilsonzlin avatar Jul 11 '20 09:07 wilsonzlin

Just an update: renamed the project to minify-html and the npm package is now only 20 KB. It only fetches the platform-specific binary, which I did some measuring:

  • core (HTML only): 2 MB, smaller than node_modules when installing html-minifier
  • js-esbuild (HTML + JS): 9 MB, same size as the esbuild package (but with free HTML minifier :smiley:)

wilsonzlin avatar Jul 11 '20 16:07 wilsonzlin

Wow that's impressive! :)

I'll take a look tonight

jantimon avatar Jul 12 '20 11:07 jantimon

Any news on this one?

eamodio avatar Feb 04 '21 23:02 eamodio

How about using https://github.com/webpack-contrib/html-minimizer-webpack-plugin to define a custom minify function?

Then remove htmlWebpackPlugin.options.minify ...

Airkro avatar Nov 09 '21 10:11 Airkro

Yes, it should be implemented on html-minimizer-webpack-plugin side, I think in future we remove HTML minification here in favor of html-minimizer-webpack-plugin, because it is more flexible and allow to compress all HTML assets, not only from html-webpack-plugin, I will add @minify-html support to html-minimizer-webpack-plugin soon

alexander-akait avatar Jun 10 '23 16:06 alexander-akait