Formats and preservation rules
“Minify” is not one algorithm. Whitespace and comments have different meanings in HTML, CSS, JavaScript, JSON and XML, so Minify++ has a separate conservative mode for each syntax family.
JavaScript
JavaScript requires lexical context. Minify++ tracks strings, templates, regex literals, comments, delimiters and statement boundaries so it can distinguish cases such as regex versus division and preserve semantics around automatic semicolon insertion.
while (ready);
const ratio = value / 2;
const ok = /[<>]/.test(text);
const msg = `value: ${ratio}`; JSX / TSX preservation
Minify++ understands enough JSX structure to safely remove formatting without compiling JSX. It preserves nested markup and JavaScript expressions, including TSX generic components and generic arrows. TypeScript syntax remains TypeScript; Minify++ is not a TS compiler.
CSS
CSS handling is designed to be future-tolerant. Strings, comments, custom properties, functions and delimiter-sensitive spaces are recognized, but Minify++ does not keep a brittle allowlist of known at-rules. Container queries, layers, native nesting, :has(), modern color syntax and custom-property token streams are in the regression suite.
HTML
HTML minification preserves text where whitespace may be visible, with special handling for raw-text elements such as <script>, <style> and <textarea>. Inline/mixed content is treated more conservatively than formatting between block structures.
JSON
JSON is parsed structurally. That lets Minify++ remove insignificant formatting without guessing inside strings and reject malformed input instead of emitting a smaller invalid document.
XML and SVG
XML/SVG preserve namespaces, entities, CDATA and meaningful text spacing. SVG is XML-like but adds plenty of attribute-heavy real-world input, so paths, namespaced attributes and preserved text have dedicated tests.
What is deliberately absent
Sass/SCSS, TypeScript and TSX compilation remain external because they are source-language transforms, not final-artifact minification. If a source format compiles to CSS or JavaScript, run that compiler first and Minify++ second.
Format contract at a glance
| Mode | Primary strategy | Notable preservation boundary |
|---|---|---|
| HTML | context-aware lexical scan | mixed text and raw-text bodies |
| CSS | token-aware lexical scan | delimiter-sensitive separation and strings |
| JavaScript | lexical/context scanner | ASI, regex/division and templates |
| JSX | JS + markup-aware scan | nested expressions and TSX-aware boundaries |
| JSON | structural parser | string values and validity |
| XML | conservative lexical scan | CDATA, entities and meaningful text |
| SVG | conservative XML-like scan | text and attribute-heavy content |
Unknown and future syntax
Minify++ prefers preservation over guessing. Supporting a filename extension is not permission to rewrite every construct that future standards may introduce. Confirmed new syntax should arrive with a minimal example, neighboring counterexamples, the strongest available oracle and a retained regression.