minify

Go minifiers for web formats

MIT License

Downloads
51K
Stars
3.6K
Committers
45

Bot releases are hidden (Show)

minify - v2.9.7

Published by tdewolff about 4 years ago

  • cmd: add JS options
  • JS: remove unassigned bindings in for statement initializer when it cannot be merged with variable declaration
  • JS: use Precision option in minifying numbers
  • SVG: fix bugs in skipping foreignObject tags
minify - v2.9.6

Published by tdewolff about 4 years ago

  • JS: add var decl as undeclared in block scopes between the current scope and the function scope, fixes #334
  • JS: fix overwriting next statement in if-else => if-if conversion, fixes #335
minify - v2.9.5

Published by tdewolff about 4 years ago

  • cmd: minify input even if extension is unknown but type/mimetype is given
  • CSS: fix timeout in property with many commas
  • CSS: convert RGBA to transparent only if the color is fully transparent black (and not any other transparent color), fixes #332
  • CSS: fix crash when rgb/rgba functions have less than three arguments
  • CSS: fix box-shadow value none conversion to 0 0 as they are not equivalent, fixes #332
  • HTML: remove space between attributes when after a quoted value
  • HTML: keep empty title and lang attributes, fixes #331
  • JS: merge variable declarations even if one has an ObjectPattern
  • JS: remove trailing commas in BindingArray (except when Rest ellipsis is set)
  • JS: add parenthesis around object literal in arrow function body, fixes #333
minify - v2.9.4

Published by tdewolff about 4 years ago

  • JS: don't remove braces when there are lexical declarations, fixes #326
  • JS: don't convert lexical declarations to expressions when hoisting variables, fixes #326
  • JS: merge variable declaration and for initializer with variable declaration
minify - v2.9.3

Published by tdewolff about 4 years ago

  • CSS: minify comma-separated lists for box-shadow, background, background-repeat, background-size, and background-position properties (fixes #322)
  • CSS/SVG: remove deprecated Decimals options in favor of Precision
  • cmd: remove --decimals options for CSS and SVG minifiers in favor of --precision
  • cmd: add --bundle option to explicitly bundle (concatenate/merge) files into one, do not asume from the -o options if it lacks a / at the end that it outputs to a file and thus needs to merge the inputs
  • cmd: directory inputs needs --recursive, previously directories would be expanded by defaults (but not their subdirectories). This matches behaviour of the cp command and will be more intuitive.
  • cmd: file inputs are copied without considering and recreating its directory path. For example, minify -o out path/to/file would output to out/path/to/file but will now output to out/file. This is the same behaviour as the cp command and will be more intuitive for users.
minify - v2.9.2

Published by tdewolff about 4 years ago

  • JS: only put var declaration into for or while, and not let nor const, fixes #325
  • JS: merge more efficiently a var declaration with a for or while statement
minify - v2.9.1

Published by tdewolff about 4 years ago

  • JS: fix parsing in identifier in group expressions
  • JS: fix parsing identifiers inside arrow function body in some cases #324
  • JS: keep all license comments at the top of the file
  • JS: minify typeof x==='undefined' to typeof x=='undefined'
  • JS: merge expressions and var declarations with for with empty initializer or with while statement converted to for
  • JS: iteratively merge if(a){return b}if(c){return d}return e chains to return a?b:c?d:e
minify - v2.9.0

Published by tdewolff about 4 years ago

  • Add JS (ECMAScript 2020) minifier
  • Improve benchmark functions
  • Predefine byte-slices instead of inline for performance
  • Don't check write errors to output during minification, but check at the end only
  • Lexers/parser now require passing parse.Input instead of io.Reader
  • Rename subpackage min to minify

JS minifier overview

Features:

  • remove superfluous whitespace
  • remove superfluous semicolons
  • shorten true, false, and undefined to !0, !1 and void 0
  • rename variables and functions to shorter names (not in global scope)
  • move var declarations to the top of the global/function scope (if more than one)
  • collapse if/else statements to expressions
  • minify conditional expressions to simpler ones
  • merge sequential expression statements to one, including into return and throw
  • remove superfluous grouping in expressions
  • shorten or remove string escapes
  • convert object key or index expression from string to identifier or decimal
  • merge concatenated strings
  • rewrite numbers (binary, octal, decimal, hexadecimal) to shorter representations

It compresses files at about 25 MB/s (only minifying, not considering reading/writing files) which is (much) faster than existing minifiers. Compression rate is between 1.5 and 3.0 depending on the file (respectively, the compression file size is between 35% -- 65% of the original). Example of known files:

File Original Size Compressed Size Ratio Time Speed
ace.js 644 kB 346 kB 53.7% 34ms 19 MB/s
dot.js 5.2 kB 3.3 kB 64.9% 563µs 9.2 MB/s
jquery.js 247 kB 85 kB 34.4% 11ms 22 MB/s
jqueryui.js 470 kB 241 kB 51.3% 26ms 18 MB/s
moment.js 99 kB 35 kB 34.9% 4ms 24 MB/s

The minifier has been tested for a number of web applications including WordPress. The go-fuzz fuzzer has been used extensively in order to detect bugs, and will continue finding bugs using https://github.com/google/oss-fuzz

minify - v2.8.0

Published by tdewolff about 4 years ago

WARNING for package maintainers, some files have been renamed, adjust your build scripts accordingly.

  • Use Makefile instead of GoReleaser to build releases for all architectures, use make release. This fixes the README.md file location inside the archives to be in the root of the archive
  • Release archives will no longer have the version name explicitly stated, fixes #316
  • Remove cmd/minify/install.sh, use make install instead
  • Rename cmd/minify/minify_bash_tab_completion to cmd/minify/bash_completion
  • Rename LICENSE.md to LICENSE as it is not a Markdown file
  • Rename min subpackage to minify
  • cmd: running minify without arguments will print a more informative error message
  • cmd: bad arguments will not display cmd usage automatically
minify - v2.7.7

Published by tdewolff about 4 years ago

  • cmd: fix file paths on Windows when input and output directories are equal (slash vs backslash)
  • cmd: add --cpuprofile and --memprofile options
  • cmd: fix usage of --match and --sync simultaneously, fixes #315
  • cmd: --match applies to all filename inputs not just under directories
  • CSS: remove whitespace around custom variable value, fixes #305
  • JSON: minify numbers, fixes #302
  • HTML: fix slow parsing of <a> tag with many name or id attributes (OSS-Fuzz)
  • Don't replace space by + in DataURI, fixes #314
  • Don't escape @ : ; = ? + , / $ \t \n \r in DataURIs (works for Chrome, Firefox, Opera, Edge, Safari, Yandex, and IE9, IE10, IE11)
minify - v2.7.6

Published by tdewolff over 4 years ago

  • HTML: remove text and whitespace within select and optgroup tags
  • CSS: fix slow parsing of selectors when they contain many errors (OSS-Fuzz)
  • CSS: fix RGB/HSL when a parameter overflows (OSS-Fuzz)
  • CSS: fix slow parsing of large HSL parameters (OSS-Fuzz)
  • cmd: properly run defer calls after command ends, may fix some race bugs
  • Add easy API in the min/ subpackage
  • Add project to OSS-Fuzz
minify - v2.7.4

Published by tdewolff over 4 years ago

  • CSS: fix minification of flex, default of flex-basis is zero for three value case, fixes #292
  • CSS: remove whitespace within @import url(...), fixes #296
  • HTML: remove spaces around/in picture and audio following whitespace removal rules for phrasing elements
minify - v2.7.3

Published by tdewolff over 4 years ago

  • external minifiers can now use input/output files instead of only stdin/stdout using the $in and $out keywords
  • SVG: don't minify inside foreignObject, fixes #291
minify - v2.7.2

Published by tdewolff almost 5 years ago

  • SVG: bugfix for C, S, Q, and T commands where if the control points would not overlap with the start or end points of the curve, it would still be converted to a line.
minify - v2.7.1

Published by tdewolff almost 5 years ago

  • DataURI: if the original data URI is shorter than the URL-encoded/base64-encoded URI, use the original instead, fixes #282
  • Bugfix: decimal (i.e. without exponentials) incorrectly minified 139.9 to 230 instead of 140
minify - v2.7.0

Published by tdewolff almost 5 years ago

  • Use custom URL encode/decode functions to fix #180 and #243
  • Decimal and Number now take precision to mean the number of significant digits, and not the number of digits behind the dot (decimals); includes a few subtle bugfixes. Decimals option renamed to Precision
  • Move Hash definitions and EntitiesMap from tdewolff/parse to this repository to prevent releasing new versions of tdewolff/parse everytime
  • cmd: add --sync functionality
  • cmd: make --watch work for newly created directories
  • cmd: various fixes and improved messages
  • CSS: keep quotes around IE font families, fixes #251
  • CSS: major refactor to allow nested functions to be minified
  • CSS: improved HSL/RGB minification
  • CSS: minify more properties: color, background-color, border-color, border-*-color, caret-color, outline-color, fill, stroke, column-rule, text-shadow, text-decoration, text-emphasis, flex, flex-*, order, fixes #217
  • CSS: minify background better if it has multiple layers
  • CSS: improve box-shadow minification
  • CSS: accept CSS functions where numbers/lengths are required, such as calc, min, max, clamp, attr, var
  • SVG: print new path command after bad command, fixes #275
  • SVG: print A command correctly with boolean largeArc and sweep
  • SVG: avoid precision errors for alternative (absolute or relative commands) path
minify - v2.6.3

Published by tdewolff almost 5 years ago

Add install.sh and Makefile to ./cmd/minify.

No changes to binaries (use v2.6.2).

minify - v2.6.2

Published by tdewolff almost 5 years ago

  • HTML: ignore CSS minification for amp-boilerplate
  • HTML: add KeepQuotes option for attributes
  • XML: bugfix for recent changes to XML parser
minify - v2.6.1

Published by tdewolff almost 5 years ago

Upgrade to tdewolff/[email protected]:

  • Re-parse input immediately when encountering parse error. Previously this was only done if the error was actually read which would save us from re-parsing the file (i.e. better performance). However, an error is (a) rare and (b) happens only once per file. Re-parsing on errors does not impact the performance of well formatted files, and a reliable error message is valued more.
  • Bugfix: prevent infinite loop on error on input file that contains unicode code points (i.e. any character bigger than 0xC0 usually followed by more bytes).
  • Improve error messages for parsers to include parser name and print offending byte(s)
minify - v2.6.0

Published by tdewolff almost 5 years ago

  • CSS: remove space after function in property value; margin:calc(10px) calc(20px) => margin:calc(10px)calc(20px)
  • SVG: parse A path command correctly when the booleans largeArc and sweep are not separated by a space, such as in A10 10 0 0120 0 which is equivalent to A10 10 0 0 1 20 0
  • SVG bugfix: make sure we are processing a valid path command
  • SVG bugfix: prevent panic when having insufficient path arguments
  • cmd: surpress error when minifying empty directory
  • HTML: only minify attributes for known HTML5 tags, fixes #270
  • HTML, XML, SVG: minify entities with [email protected] such as: &quot; => ", &#34; => ", &#x22; => ", &rsquor; => &rsquo;, &#x270F; => &#9999;.
Package Rankings
Top 0.74% on Proxy.golang.org
Top 4.62% on Pypi.org
Top 6.62% on Alpine-edge
Top 8.91% on Alpine-v3.16
Top 9.39% on Alpine-v3.17
Top 2.74% on Alpine-v3.18
Top 3.27% on Npmjs.org
Badges
Extracted from project README
API reference Go Report Card codecov SiteGround