GUIDE深度 · Deep dive
Which HTML Whitespace Matters
HTML collapses repeated whitespace by default, but pre and textarea preserve it, and whitespace in script/style can be syntactic; a single space between inline elements renders as a gap.
Must preserve
pre/textarea: displayed as-is.
script/style: whitespace in strings and selectors.
Whitespace inside these elements is content, not formatting.
Easy to miss
There is a space between <span>a</span> <span>b</span>.
Gaps in inline-block layouts.
Browsers collapse whitespace differently at different widths, so test desktop and mobile.
FAQ
How to minify safely?
Use mature tools and visual regression tests; avoid hand-written regex.
Why garbled Chinese after minifying?
Check that the encoding declaration matches the file encoding.