2

How can I minify an html string on client side with html minifier ?

I already take a look to html-minifier it work well on node.js but i don't know if it's possible to use it in browser environnement.

Anyone can provide a working example ?

ZecKa
  • 2,552
  • 2
  • 21
  • 39
  • Can you try this: https://stackoverflow.com/questions/36606082/clientside-html-minification You can have a function on the client side that takes the html string and uses `String.replace(/\n[ ]*/g,"")` to do the minification. Not the best solution, but client-side minification isn't really ideal to begin with. – Amats Dec 17 '20 at 15:15
  • Yep i already see. But in fact my goal is to use html minifier in front end part. I can not do it in backend because I generate html in frontend part. My project is a webapp who generate html template dynamically with form value. – ZecKa Dec 17 '20 at 15:22
  • 1
    You could modify a version of `html-minifier` to have it attach the global `window` and expose it, then host it on a CDN that you can just refer to on the client side. Though that's too much. Have you tried [Browserify](http://browserify.org/)? – Amats Dec 17 '20 at 16:26
  • 2
    Finaly find a solution, here is a working example: https://codesandbox.io/s/html-minifier-in-browser-client-side-html-minification-tj7i0 – ZecKa Jan 05 '21 at 08:29

0 Answers0