One of the things that has occurred to me more recently is that if you add up all of the bandwidth that is taken up by thousands of users downloading the newlines and tabs used to make HTML source code readable... that's a LOT of wasted bandwidth.
So I wanted to add some code that would condense whitespace on-the-fly before sending it to the browser.
I then very quickly realised that sometimes, whitespace is significant. For example, in
After double-checking, I've come to the firm conclusion that there is absolutely no use of
white-space CSS values such as
pre-wrap that would make whitespace significant, except in the case of a custom
So with that in mind, I wanted to condense whitespace that is not contained in a
<rainbow>. I accomplished this with
DOMDocument and a
DOMXPath, in other words, "doing it right". But then I learned about regex verbs, and replaced my code with this:
// uber hax with regex $str = trim(preg_replace("(<(textarea|rainbow|pre).*?</\\1>(*SKIP)(*F)|\s+)s"," ",$str));
It, um... well, it works, or at least it seems to from what I can tell. But I wanted to post here so I can ask, have I missed anything important? Or is it really this simple?