⚡ Curated dev resources & dealsSponsored
DevToolBayFree Developer Tools

Minifying JSON and CSS Safely: What Must Never Be Removed

What minifiers are allowed to touch: whitespace rules in JSON, strings and url() in CSS, real-world savings numbers and a pre-flight validation checklist.

Minification is deletion with a contract: remove what parsers ignore, never what they read. Breaking the contract ships broken assets — so it is worth knowing what the safe boundary looks like.

JSON: whitespace outside strings, nothing else

Valid minification removes indentation, line breaks and spaces around punctuation outside string values. Inside strings, every byte is data — a minifier that reformats them changes your payload. The JSON Minifier validates first and reports exact savings, so corrupt input never produces a plausible-looking file.

CSS: the exceptions list

  • Strings and url() values: a space inside a font name or data URI is content.
  • @media conditions: removing the space in and ( breaks parsing.
  • .calc() expressions: calc(100% - 8px) needs those spaces — minus signs bind to numbers.
  • Custom properties and var(): valid, but values live in strings more than people expect.

The CSS Formatter & Minifier implements exactly that boundary and keeps colors and selectors intact while compacting the rest.

What savings to expect

InputTypical shrink
Pretty-printed JSON (2-space indent)30-60 percent
Hand-written CSS with comments20-40 percent
Already-compact CSS5-10 percent

Note what minification is not: compression. Transport gzip or brotli on top — and measure with real files, since whitespace-heavy documents gain less once compressed.

The pre-flight checklist

  1. Validate the source first — the JSON Validator pinpoints syntax errors with line and column.
  2. Minify a copy, never your editing source.
  3. Keep the pretty version in version control and minify at deploy.

Related guides

Try these tools