{"id":13712037,"url":"https://github.com/middlewares/minifier","last_synced_at":"2026-01-07T23:54:54.868Z","repository":{"id":55506861,"uuid":"70502889","full_name":"middlewares/minifier","owner":"middlewares","description":"Middleware to minify Html, CSS and Javascript responses","archived":false,"fork":false,"pushed_at":"2025-03-26T14:44:07.000Z","size":48,"stargazers_count":17,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T15:44:20.069Z","etag":null,"topics":["compress","http","middleware","minify","psr-15","uglify"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/middlewares.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2016-10-10T15:42:44.000Z","updated_at":"2025-03-23T10:29:04.000Z","dependencies_parsed_at":"2024-01-12T22:36:55.170Z","dependency_job_id":"996f3709-0ee9-44a8-9d12-1e067e52f40a","html_url":"https://github.com/middlewares/minifier","commit_stats":{"total_commits":54,"total_committers":4,"mean_commits":13.5,"dds":0.09259259259259256,"last_synced_commit":"16809ce2462cd4636b2e9fc8bbf48b57f1521bad"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Fminifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Fminifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Fminifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Fminifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/middlewares","download_url":"https://codeload.github.com/middlewares/minifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252772248,"owners_count":21801889,"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":["compress","http","middleware","minify","psr-15","uglify"],"created_at":"2024-08-02T23:01:14.293Z","updated_at":"2026-01-07T23:54:54.838Z","avatar_url":"https://github.com/middlewares.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Content"],"readme":"# middlewares/minifier\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE)\n![Testing][ico-ga]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nMiddleware to minify the `Html`, `CSS` and `Javascript` content using [wyrihaximus/compress](https://github.com/WyriHaximus/php-compress) and the following compressors by default:\n\n- [wyrihaximus/html-compress](https://github.com/WyriHaximus/HtmlCompress)\n- [wyrihaximus/css-compress](https://github.com/WyriHaximus/php-css-compress)\n- [wyrihaximus/js-compress](https://github.com/WyriHaximus/php-js-compress)\n\n## Requirements\n\n* PHP \u003e= 7.2\n* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)\n* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)\n\n## Installation\n\nThis package is installable and autoloadable via Composer as [middlewares/minifier](https://packagist.org/packages/middlewares/minifier).\n\n```sh\ncomposer require middlewares/minifier\n```\n\n## Example\n\n```php\nDispatcher::run([\n    Middlewares\\Minifier::html(),\n    Middlewares\\Minifier::css(),\n    Middlewares\\Minifier::js(),\n]);\n```\n\n## Usage\n\nThis middleware minify the code of http responses using any compressor implementing the `WyriHaximus\\Compress\\CompressorInterface`. The code format is detected from the `Content-Type` header, so make sure your responses contains this header (you may want to use [middlewares/negotiation](https://github.com/middlewares/negotiation) for that).\n\n```php\nuse WyriHaximus\\HtmlCompress\\Factory;\n\n$compressor = Factory::construct();\n$mimeType = 'text/html';\n\n$minifier = new Middlewares\\Minifier($compressor, $mimeType);\n```\n\nOptionally, you can provide a `Psr\\Http\\Message\\StreamFactoryInterface` as third argument to create the response body. If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.\n\n```php\n$streamFactory = new MyOwnStreamFactory();\n\n$minifier = new Middlewares\\Minifier($compressor, $mimeType, $streamFactory);\n```\n\n### Helpers\n\nThree static functions are provided to create instances of this middleware with common configuration for html, css and js responses:\n\n```php\n$htmlMinifier = Middlewares\\Minifier::html();\n$cssMinifier = Middlewares\\Minifier::css();\n$jsMinifier = Middlewares\\Minifier::js();\n```\n\n---\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/middlewares/minifier.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-ga]: https://github.com/middlewares/minifier/workflows/testing/badge.svg\n[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/minifier.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/middlewares/minifier\n[link-downloads]: https://packagist.org/packages/middlewares/minifier\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Fminifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiddlewares%2Fminifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Fminifier/lists"}