Can someone help me with a Perl or dynamic module to strip of whitespaces & comments from html responses in nginx?
Looks like there's a module to strip whitespace (not comments apparently)
As Ochoto already said, this should be done at deploy, or better, at render time. Because sometimes you might have spaces (non- ) which are needed in order to display the page correctly. If you do this at a later stage, you can run into troubles (it can also work)
Anyway, if payload-size is your issue, have a look at compression. This will produce far better results in my opinion.
This can be extremely tricky!
You should not only be aware of
<pre> tags, but consider stuff like this:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <text x="0" y="15" xml:space="preserve">hello world</text> </svg>
Your post-processor would really need to parse the content and understand it. A simple regular expression will surely mess things up sooner or later.
As Cohoto and Franz Bettag have mentioned, this should aether be done in the source or as a pre-deployment step and not as a post-processing fix-up.