To the Directors of White Space

Dear Sirs,

It has come to my attention that our White Space is running wild. Would it be possible to tame that beast back into submission please.

Seriously, I would like to propose adding another rule to the coding standards: when outputting HTMLHTML HyperText Markup Language. The semantic scripting language primarily used for outputting content in web browsers. directly, leave all white space in PHPPHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 or higher. Currently we do something like this:

if ( something ) {
    ?>
    <div id=...>some more</div>
    <div id=...>even more</div>
    <?php
}

That’s all nicely readable on the PHP side but the outputted HTML is surrounded by quite a bit of redundant space. What I’m proposing is to stop/start PHP immediately around the HTML:

if ( something ) {
    ?><div id=...>some more</div><?php
    ?><div id=...>even more</div><?php
}

This doesn’t impact the readability on the PHP side and produces “tight” HTML with no white spaces as it should be for production. In fact the HTML source would be “pseudo-minified”.

Of course the readability of the HTML source will be affected but not that much. Currently our HTML output is all over the place which makes it pretty hard to read. Considering that most people never look at the HTML source directly any more thanks to FIrebug and friends and all coding oriented text editors have a function to reformat HTML, I believe outputting “minified” HTML is an advantage. This also reduces the size of our output from 3% to 15% depending on the page.

Of course I’m not proposing for everybody to rush and reformat the whole codebase if this is accepted. But we can apply it to new code and clean up functions that are being patched for other reasons.

#optimization