{"id":22423292,"url":"https://github.com/prantlf/minified-size","last_synced_at":"2025-08-01T07:32:08.963Z","repository":{"id":57297791,"uuid":"146819875","full_name":"prantlf/minified-size","owner":"prantlf","description":"Estimates the size of minified and gzipped/brotlied JavaScript, CSS and HTML files.","archived":false,"fork":false,"pushed_at":"2023-12-10T18:15:09.000Z","size":570,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-02T21:47:27.678Z","etag":null,"topics":["brotli","brotlied-files","css","estimate","files","gzip","gzipped-files","html","minify","size","size-calculation","stylesheets"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-31T00:10:17.000Z","updated_at":"2022-10-23T20:21:57.000Z","dependencies_parsed_at":"2024-06-19T17:54:10.467Z","dependency_job_id":null,"html_url":"https://github.com/prantlf/minified-size","commit_stats":{"total_commits":66,"total_committers":2,"mean_commits":33.0,"dds":"0.030303030303030276","last_synced_commit":"3d6be9013d624ecb35919e4b08f1b043f1a030b4"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fminified-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fminified-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fminified-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fminified-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/minified-size/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228348371,"owners_count":17905899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brotli","brotlied-files","css","estimate","files","gzip","gzipped-files","html","minify","size","size-calculation","stylesheets"],"created_at":"2024-12-05T18:09:54.590Z","updated_at":"2025-08-01T07:32:08.953Z","avatar_url":"https://github.com/prantlf.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# minified-size\n[![NPM version](https://badge.fury.io/js/minified-size.png)](http://badge.fury.io/js/minified-size)\n[![Build Status](https://github.com/prantlf/minified-size/workflows/Test/badge.svg)](https://github.com/prantlf/minified-size/actions)\n[![codecov](https://codecov.io/gh/prantlf/minified-size/branch/master/graph/badge.svg)](https://codecov.io/gh/prantlf/minified-size)\n[![Maintainability](https://api.codeclimate.com/v1/badges/8b145cbcf64c31ea8904/maintainability)](https://codeclimate.com/github/prantlf/minified-size/maintainability)\n[![Dependency Status](https://david-dm.org/prantlf/minified-size.svg)](https://david-dm.org/prantlf/minified-size)\n[![devDependency Status](https://david-dm.org/prantlf/minified-size/dev-status.svg)](https://david-dm.org/prantlf/minified-size#info=devDependencies)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nEstimates the size of minified and gzipped/brotlied JavaScript, CSS and HTML files [very fast](#performance). Check, how much space will a particular source take in the minified output.\n\n- [Command-line Usage](#command-line-usage)\n- [Programmatic Usage](#programmatic-usage)\n- [Performance](#performance)\n- [Contributing](#contributing)\n- [Release History](#release-history)\n- [License](#license)\n\n**Note:** If you use Node.js 8 or 9, install a version `1.x`. Versions `2.x` require Node.js 10 or newer. (They need support for asynchronous generators.)\n\n## Command-line Usage\n\nMake sure that you have [Node.js] \u003e= 10 installed. Install the `minified-size` package globally by your favourite package manager:\n\n```text\nnpm i -g minified-size\npnpm i -g minified-size\nyarn global add minified-size\n```\n\nPrint the original, expected minified, gzipped and brotlied sizes of a sample file:\n\n```text\n$ minified-size lib/index.js\nlib/index.js: 10.8 kB, 5.09 kB, 2.12 kB, 1.86 kB\n```\n\nRunning `minified-size` without any parameters will print usage instructions:\n\n```text\nUsage: minified-size [options] \u003cfile\u003e, ... | --\n\nOptions:\n\n-V, --version              output the version number\n-l, --language [name]      specifies the input language (default: \"js\")\n-j, --json                 print results in the JSON format\n-r, --raw-sizes            print sizes in bytes as integers\n-o, --no-original-size     prevents printing the size of the original code\n-m, --no-minified-size     prevents printing the size of the minified code\n-g, --no-gzipped-size      prevents printing the size of the gzipped code\n-b, --no-brotlied-size     prevents printing the size of the brotlied code\n-s, --source-type [type]   sets JavaScript source type (module or script)\n-t, --no-total             prevents printing the total sizes\n-i, --minifier [minifier]  chooses the JavaScript minifier (default: \"swc\")\n-h, --help                 display help for command\n\nAll four sizes are estimated by default. File paths may contain wildcards.\nIf \"--\" is entered instead of files, the standard input will be read.\nStylesheets are recognized by the extension \".css\", or they can be forced\nby the language \"css\" on the command line. Web pages are recognized by the\nextension \".htm[l]\", or they can be forced by the language \"html\".\nThe JavaScript minifier can be \"swc\", \"esbuild\", \"terser\" or \"babel\".\n```\n\n### Errors\n\nIf parsing of the input or its minification fails, a colourful error message with additional information will be printed instead of the computed sizes. For example, a typo \"exort\" instead of \"ex**p**ort\":\n\n```text\n$ minified-size test/invalid.js\ntest/invalid.js(1,7): unknown: Unexpected token, expected \";\"\n\n\u003e 1 | exort default {\n    |       ^\n  2 |   \"compressed\": \"\n  3 | \"\n  4 | }` } ]\n```\n\n## Programmatic Usage\n\nMake sure that you use [Node.js] \u003e= 16. Install the `minified-size` package locally by your favourite package manager:\n\n```bash\nnpm i minified-size\npnpm i minified-size\nyarn add minified-size\n```\n\nGet the original, expected minified, gzipped and brotlied sizes (in bytes) of a sample file:\n\n```javascript\nconst { getMinifiedSizes } = require('minified-size')\nconst results = await getMinifiedSizes({ files: [ 'lib/index.js' ] })\n// [ { file: 'lib/index.js',\n//     originalSize: 10788,\n//     minifiedSize: 5087,\n//     gzippedSize: 2122,\n//     brotliedSize: 1861 } ]\n```\n\nIf you process a lot of files, you can use an asynchronous generator, which yields results one-by-one to get them earlier, instead of returning an array with all of them together:\n\n```javascript\nconst { generateMinifiedSizes } = require('minified-size')\nconst resultGenerator = generateMinifiedSizes({\n  files: [ 'public/**/*.(js|css|html)' ]\n})\nfor (;;) {\n  const result = await resultGenerator.next()\n  if (result.done) {\n    break\n  }\n  const {\n    error, file, originalSize, minifiedSize, gzippedSize, brotliedSize\n  } = result.value\n  if (error) {\n    console.info(`${file}: ${originalSize}, ${minifiedSize}, ${gzippedSize}, ${brotliedSize}`)\n  } else {\n    console.error(`${file}: ${error}`)\n  }\n}\n```\n\nYou can compute total sizes from all file results:\n\n```javascript\nconst { getMinifiedSizes, computeTotalSizes } = require('minified-size')\nconst results = await getMinifiedSizes({ files: [ 'foo.js', 'bar.js' ] })\nconst total = computeTotalSizes(results)\n// { total: true,\n//   originalSize: 89745,\n//   minifiedSize: 8562,\n//   gzippedSize: 2341,\n//   brotliedSize: 2065 }\n```\n\n### Options\n\n* `language` - a string specifying the input language (\"js\", \"css\" or \"html\")\n* `files` - an array of strings with file paths to load and process\n* `streams` - an array of readable streams with source code to process\n* `sources` - an array of strings with source code to process\n* `gzip` - a boolean to disable estimating the gzipped output size, or an object with [options for gzip].\n* `brotli` - a boolean to disable estimating the brotlied output size, or an object with [parameters for brotli].\n* `minifier` - a string choosing the JavaScript minifier (\"swc\" - default, \"esbuild\", \"terser\" or \"babel\")\n\n### Errors\n\nIf parsing of the input or its minification fails, the returned object will contain an `error` key instead of the computed sizes:\n\n```javascript\nconst minifiedSize = require('minified-size')\nconst files = [ 'test/invalid.js' ]\nconst results = await minifiedSize({ files })\n// [ { file: 'test/invalid.js',\n//     error: {\n//       reason: 'unknown: Unexpected token, expected \";\"',\n//       line: 1,\n//       column: 7,\n//       message: `test/invalid.js(1,7): unknown: Unexpected token, expected \";\"\n//\n// \u003e 1 | exort default {\n//     |       ^\n//   2 |   \"compressed\": \"\n//   3 | \"\n//   4 | }` } ]\n```\n\n## Unicode\n\nLet us say, that you minify scripts using UTF-8 literals a lot:\n\n```js\nmessage = \"䅬朤堾...\"\n```\n\nIf you run such input through [babel-minify], you may become a lot bigger output instead of a smaller one, because it escapes non-latin characters:\n\n```js\nmessage=\"\\u416C\\u6724\\u583E\\u605B\\u0825\\u6120\\u4C20...\"\n```\n\nLook for an option, that will make your minifier retain the Unicode literals unchanged, or converts all escaped Unicode code points to literals. You could also post-process the minified output yourself by the following method:\n\n```js\nfunction replaceEscapedUnicodeCharacters (source) {\n  return source.replace(/\\\\u([\\w]{4})/gi, (match, code) =\u003e\n    String.fromCharCode(Number.parseInt(code, 16)))\n}\n```\n\nThe size computation done by `minified-size` uses the function above to ensure correct results until the issue [babel-minify/619] is resolved.\n\nOther minifiers ([swc], [esbuild] and [terser]) do not suffer from this issue. ([esbuild] needs the option `charset=utf8` added.)\n\n## Performance\n\nThe JavaScript minifier affects the performance the most. The most efficient one is [swc], but because it cannot minify both modules and scripts using the same options, [esbuild] is used by default. Other minifiers ([esbuild], [swc], [terser] and [babel-minify]) can be chosen as a workaround by the `minifier` option, if the default minifier cannot process some source, or just to compare the results of the minifiers.\n\nAn example of measuring a cocktail of 6.6 MB in 69 JavaScript libraries (Require, Underscore, jQuery, Backbone, Backbone.Radio, Handlebars, Marionette, Moment, Moment-Timezone, Ally, Hammer, Less etc.) shows the huge difference between the minifiers:\n\n```text\n$ time minified-size -ogbr -i swc libs/*.js\n...\ntotal: 2924862\n2.12s user 0.40s system 134% cpu 1.868 total\n\n$ time minified-size -ogbr -i esbuild libs/*.js\n...\ntotal: 2961126\n1.02s user 0.25s system 125% cpu 1.012 total\n\n$ time minified-size -ogbr -i terser libs/*.js\n...\ntotal: 2953313\n15.07s user 0.42s system 167% cpu 9.273 total\n\n$ time minified-size -ogbr -i babel libs/*.js\n...\ntotal: 2966286\n32.77s user 1.14s system 143% cpu 23.651 total\n```\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style.  Add unit tests for any new or changed functionality. Lint and test your code using Grunt.\n\n## License\n\nCopyright (c) 2018-2025 Ferdinand Prantl\n\nLicensed under the MIT license.\n\n[Node.js]: http://nodejs.org/\n[options for gzip]: https://nodejs.org/docs/latest-v10.x/api/zlib.html#zlib_class_options\n[parameters for brotli]: https://nodejs.org/docs/latest-v10.x/api/zlib.html#zlib_compressor_options\n[babel-minify/619]: https://github.com/babel/minify/issues/619\n[swc]: https://swc.rs/docs/configuration/minification\n[esbuild]: https://github.com/evanw/esbuild#readme\n[terser]: https://github.com/terser/terser#readme\n[babel-minify]: https://github.com/babel/minify#readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fminified-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fminified-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fminified-size/lists"}