{"id":15646184,"url":"https://github.com/kikobeats/http-compression","last_synced_at":"2025-04-05T14:04:19.468Z","repository":{"id":65345118,"uuid":"590228938","full_name":"Kikobeats/http-compression","owner":"Kikobeats","description":"Adding compression (gzip/brotli) for your HTTP server in Node.js.","archived":false,"fork":false,"pushed_at":"2024-10-07T16:00:44.000Z","size":71,"stargazers_count":53,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T13:06:23.437Z","etag":null,"topics":["brotli","compression","express","expressjs","gzip","https","javascript","middleware","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Kikobeats.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-01-17T23:33:33.000Z","updated_at":"2024-12-14T11:16:24.000Z","dependencies_parsed_at":"2023-02-14T12:20:34.586Z","dependency_job_id":"4befef85-0111-44f4-a923-8ea0d4c3f0a6","html_url":"https://github.com/Kikobeats/http-compression","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fhttp-compression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fhttp-compression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fhttp-compression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fhttp-compression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kikobeats","download_url":"https://codeload.github.com/Kikobeats/http-compression/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345850,"owners_count":20924102,"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","compression","express","expressjs","gzip","https","javascript","middleware","nodejs"],"created_at":"2024-10-03T12:11:43.426Z","updated_at":"2025-04-05T14:04:19.444Z","avatar_url":"https://github.com/Kikobeats.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-compression\n\n![Last version](https://img.shields.io/github/tag/Kikobeats/http-compression.svg?style=flat-square)\n[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/http-compression.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/http-compression)\n[![NPM Status](https://img.shields.io/npm/dm/http-compression.svg?style=flat-square)](https://www.npmjs.org/package/http-compression)\n\n**http-compression** adds compression for your HTTP server in Node.js by:\n\n- No dependencies (\u003c 1kB).\n- Express style middleware support.\n- Auto detect the best encoding to use (gzip/brotli).\n\n## Install\n\n```bash\n$ npm install http-compression --save\n```\n\n## Usage\n\nIf you are using an Express style framework, you can add it as middlware:\n\n```js\nconst compression = require('http-compression')\nconst express = require('express')\n\nexpress()\n  .use(compression({ /* see options below */ }))\n  .use((req, res) =\u003e {\n    // this will get compressed:\n    res.end('hello world!'.repeat(1000))\n  })\n  .listen(3000)\n```\n\nOtherwise, just pass `req, res` primitives to it:\n\n```js\nconst compression = require('http-compression')({ /* see options below */ })\nconst { createServer } = require('http')\n\nconst server = createServer((req, res) =\u003e {\n  compression(req, res)\n  res.end('hello world!'.repeat(1000))\n})\n\nserver.listen(3000, () =\u003e {\n  console.log('\u003e Listening at http://localhost:3000')\n})\n```\n\n## API\n\nThe `compression(options)` function returns an Express style middleware of the form `(req, res, next)`.\n\n### Options\n\n#### threshold\n\nType: `Number`\u003cbr\u003e\nDefault: `1024`\n\nResponses below this threshold (in bytes) are not compressed. The default value of `1024` is recommended, and avoids sharply diminishing compression returns.\n\n#### level\n\nType: `object`\u003cbr\u003e\nDefault: `{ brotli: 1, gzip: 1 }`\n\nThe compression effort/level/quality setting, used by both Gzip and Brotli. The scale range is:\n\n- brotli: from 0 to 11.\n- gzip: from -1 to 9.\n\nThe library uses uses the most efficiency level by default determined by a [benchmark](bencharmk/index.mjs).\n\n#### brotli\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\n\nEnables response compression using Brotli for requests that support it. as determined by the `Accept-Encoding` request header.\n\n#### gzip\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\n\nEnables response compression using Gzip for requests that support it, as determined by the `Accept-Encoding` request header.\n\n#### mimes\n\nType: `RegExp`\u003cbr\u003e\nDefault: `/text|javascript|\\/json|xml/i`\n\nThe `Content-Type` response header is evaluated against this Regular Expression to determine if it is a MIME type that should be compressed.\nRemember that compression is generally only effective on textual content.\n\n## License\n\nThanks to [developit](https://github.com/developit) for written the original code implementation for [polka#148](https://github.com/lukeed/polka/pull/148).\n\n**http-compression** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/http-compression/blob/master/LICENSE.md) License.\u003cbr\u003e\nAuthored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/Kikobeats/http-compression/contributors).\n\n\u003e [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/Kikobeats) · X [@Kikobeats](https://x.com/Kikobeats)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikobeats%2Fhttp-compression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkikobeats%2Fhttp-compression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikobeats%2Fhttp-compression/lists"}