Does anyone know any good java library (or single method) that can strip extra spaces (line breaks, tabs, etc) from an html file? So html file gets turned into 1 line basically.
Thanks.
UPDATE: Looks like there is no library that does that so I created my own open source project for solving this task: http://code.google.com/p/htmlcompressor/
Personally, I just enabled HTTP compression in the server and I leave my HTML readable.
But for what you want, you could just use String.replaceAll() with a regex that matching what you have specified. Off the top of my head, something like:
small=large.replaceAll("\\s{2,}"," ");
Looks like there is no library that does that so I created my own open source project for solving this task, maybe someone will find it helpful: http://code.google.com/p/htmlcompressor/
Be careful with that. Text inside pre and textarea elements will be damaged. In addition, inlined javascript inside script elements will have to be ended with column;. Lastly if you code inlined javascript with html comments (to avoid some old browser buggy behavior) this will eventually comment out the whole inlined javascript code.
Why do you want to do that? If you want to decrease the download size of the html then all you need is a GZIP filter.
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