{"id":24408590,"url":"https://github.com/jenstornell/tiny-html-minifier","last_synced_at":"2025-04-09T17:26:24.376Z","repository":{"id":41086520,"uuid":"107672257","full_name":"jenstornell/tiny-html-minifier","owner":"jenstornell","description":"Minify HTML in PHP with just a single class","archived":false,"fork":false,"pushed_at":"2023-12-03T14:56:10.000Z","size":42,"stargazers_count":184,"open_issues_count":20,"forks_count":64,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-02T11:45:12.708Z","etag":null,"topics":["compress","html","minify","minify-html","shrink"],"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/jenstornell.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":"2017-10-20T11:54:07.000Z","updated_at":"2025-03-02T15:30:42.000Z","dependencies_parsed_at":"2025-01-31T17:35:10.865Z","dependency_job_id":"50efd4da-8cdf-407c-b060-8225b3f8b5e5","html_url":"https://github.com/jenstornell/tiny-html-minifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenstornell%2Ftiny-html-minifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenstornell%2Ftiny-html-minifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenstornell%2Ftiny-html-minifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenstornell%2Ftiny-html-minifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenstornell","download_url":"https://codeload.github.com/jenstornell/tiny-html-minifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248076236,"owners_count":21043733,"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","html","minify","minify-html","shrink"],"created_at":"2025-01-20T05:52:18.727Z","updated_at":"2025-04-09T17:26:24.345Z","avatar_url":"https://github.com/jenstornell.png","language":"PHP","funding_links":["https://www.paypal.me/DevoneraAB"],"categories":[],"sub_categories":[],"readme":"# Tiny Html Minifier\n\n![Version 2.2](https://img.shields.io/badge/version-2.2-blue.svg) ![MIT license](https://img.shields.io/badge/license-MIT-green.svg) [![Donate](https://img.shields.io/badge/give-donation-yellow.svg)](https://www.paypal.me/DevoneraAB)\n\n[Changelog](changelog.md)\n\n## In short\n\n- A HTML minifier in PHP.\n- It's really really fast.\n- Only 1 file is required.\n- Almost no regular expressions.\n- Almost no options.\n\n## Details - What the minifier does\n\n- Remove HTML comments.\n- Remove slash in self closing elements. ` /\u003e` becomes `\u003e`.\n- Remove ` type=\"text/css\"` and `type=\"text/javascript\"` in `style` and `script` tags.\n- Minimize elements within `\u003chead\u003e\u003c/head\u003e`. It will not keep any whitespace (except inside `script`).\n- Minimize elements within `\u003cbody\u003e\u003c/body\u003e` but keep spaces between tags to preserve inline data (optional).\n- Minimize inline SVG files (which are a bunch of XML tags).\n- Minimize Custom Elements. They look like this: `\u003cmy-element\u003eMy content\u003c/my-element\u003e`.\n- Skip `code`, `pre`, `script` and `textarea` from being minified.\n\n## Install \u0026 usage\n\n### 1. Download\n\n**ZIP**\n\nDownload `tiny-html-minifier.php` or the whole ZIP.\n\n**Composer**\n\nYou can install it with Composer as well.\n\n### 2. Add the code\n\n```php\n\u003c?php\nrequire 'tiny-html-minifier.php';\necho TinyMinify::html($html);\n```\n\n## Before / after\n\n### Before\n\n```html\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n\n\u003cmeta charset=\"utf-8\" /\u003e\n\u003cmeta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\" /\u003e\n\n\u003clink href=\"http://example.com/style.css\" rel=\"stylesheet\" /\u003e\n\u003clink rel=\"icon\" href=\"http://example.com/favicon.png\" /\u003e\n\n\u003ctitle\u003eTiny Html Minifier\u003c/title\u003e\n\n\u003c/head\u003e\n\u003cbody class=\"body\"\u003e\n\n\u003cdiv class=\"main-wrap\"\u003e\n    \u003cmain\u003e\n        \u003ctextarea\u003e\n            Some text\n            with newlines\n            and some spaces\n        \u003c/textarea\u003e\n\n        \u003cdiv class=\"test\"\u003e\n            \u003cp\u003eThis text\u003c/p\u003e\n            \u003cp\u003eshould not\u003c/p\u003e\n            \u003cp\u003ewrap on multiple lines\u003c/p\u003e\n        \u003c/div\u003e\n    \u003c/main\u003e\n\u003c/div\u003e\n\u003cscript\u003e\n    console.log('Script tags are not minified');\n    console.log('This is inside a script tag');\n\u003c/script\u003e\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### After\n\n```html\n\u003c!doctype html\u003e\u003chtml lang=\"en\"\u003e\u003chead\u003e\u003cmeta charset=\"utf-8\"\u003e\u003cmeta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\"\u003e\u003clink href=\"http://example.com/style.css\" rel=\"stylesheet\"\u003e\u003clink rel=\"icon\" href=\"http://example.com/favicon.png\"\u003e\u003ctitle\u003eTiny Html Minifier\u003c/title\u003e\u003c/head\u003e \u003cbody class=\"body\"\u003e\u003cdiv class=\"main-wrap\"\u003e \u003cmain\u003e \u003ctextarea\u003e\n            Some text\n            with newlines\n            and some spaces\n        \u003c/textarea\u003e \u003cdiv class=\"test\"\u003e \u003cp\u003eThis text\u003c/p\u003e \u003cp\u003eshould not\u003c/p\u003e \u003cp\u003ewrap on multiple lines\u003c/p\u003e \u003c/div\u003e \u003c/main\u003e \u003c/div\u003e \u003cscript\u003e\n    console.log('Script tags are not minified');\n    console.log('This is inside a script tag');\n\u003c/script\u003e\u003c/body\u003e\u003c/html\u003e\n```\n\n## Options\n\n```php\n\u003c?php\nrequire 'tiny-html-minifier.php';\necho TinyMinify::html($html, $options = [\n    'collapse_whitespace' =\u003e false,\n    'disable_comments' =\u003e false,\n]);\n```\n\n### collapse_whitespace\n\n#### Not collapsed\n\nSpaces are preserved (except for most elements within `\u003chead\u003e\u003c/head\u003e`). It's good when using the elements inline. This is the default.\n\n```html\n\u003cul\u003e\u003cli\u003e \u003ca href=\"#\"\u003e My link \u003c/a\u003e\u003c/li\u003e\u003cli\u003e \u003ca href=\"#\"\u003e My link \u003c/a\u003e\u003c/li\u003e \u003c/ul\u003e\n```\n\n#### Collapsed\n\nSpaces are collapsed. The text inside the element is still untouched. Set this value to `true` and you will save a few extra bytes.\n\n```html\n\u003cul\u003e\u003cli\u003e\u003ca href=\"#\"\u003eMy link\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"#\"\u003eMy link\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\n```\n\n## Requirements\n\n- PHP7+\n\n## Disclaimer\n\nThis plugin is provided \"as is\" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/jenstornell/tiny-html-minifier/issues/new).\n\n## License\n\n[MIT](https://github.com/jenstornell/tiny-html-minifier/blob/master/license)\n\nIt is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.\n\n## Donate\n\nIf you want to make a donation, you can do that by sending any amount https://www.paypal.me/DevoneraAB\n\n## Credits\n\n- [Jens Törnell](https://github.com/jenstornell)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenstornell%2Ftiny-html-minifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenstornell%2Ftiny-html-minifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenstornell%2Ftiny-html-minifier/lists"}