HTML Minification: Whitespace between element attributes

I’d like to remove more unnecessary bytes from my output, and it seems it’s acceptable (in practice) to strip what can add up to quite a lot of whitespace from HTML markup by omitting/collapsing the gaps between DOM element attributes.

Although I’ve tested and researched (a little in both cases), I’m wondering how safe it would be?

I tested in Chrome (43.0.2357.65 m), IE (11.0.9600.17801), FF (38.0.1) and Safari (5.1.7 (blah-di-blah)) and they didn’t seem to mind, and couldn’t find anything specific in The Specs about whitespace between attributes.

I noted also that someone’s HTML compressor could (when enabled) strip quotes around attribute values where those values had no whitespace within them (e.g. id), which implies that at least most if not all HTML parsing is focussed on the text either side of the equals signs (except with booleans of course), and where quotes are in use, they’d be considered the prioritized delimiter.

So, would:

<!DOCTYPE html><html><body>
<a href=""target="_blank"title="This is a test">Yabba Dabba Doo!</a>

▲ that ever go wrong, and if so, under which conditions?

What other reasons could there be to maintain this whitespace in production output (code “readability” is a non issue in this case)?

Source: cross-browser

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.