{"id":23412827,"url":"https://github.com/codyverse/shrinkwrap","last_synced_at":"2025-04-09T04:11:53.857Z","repository":{"id":209516560,"uuid":"722704531","full_name":"codyverse/shrinkwrap","owner":"codyverse","description":"All-in-one web page minifier (HTML/JS/CSS), in PHP.","archived":false,"fork":false,"pushed_at":"2024-01-10T04:42:55.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T22:31:54.253Z","etag":null,"topics":["css-minification","css-minifier","html-minification","html-minifier","html-minify","js-minification","js-minifier","mini","minifier","minify-css","minify-html","minify-javascript","minify-js","php"],"latest_commit_sha":null,"homepage":"","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/codyverse.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":"2023-11-23T18:38:03.000Z","updated_at":"2024-02-11T15:26:10.000Z","dependencies_parsed_at":"2023-12-04T11:25:58.278Z","dependency_job_id":"0c3bbce6-3b10-4527-b73d-bfe59ef259f5","html_url":"https://github.com/codyverse/shrinkwrap","commit_stats":null,"previous_names":["fpvcode/shrinkwrap","codyverse/shrinkwrap"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyverse%2Fshrinkwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyverse%2Fshrinkwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyverse%2Fshrinkwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyverse%2Fshrinkwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codyverse","download_url":"https://codeload.github.com/codyverse/shrinkwrap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974732,"owners_count":21026742,"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":["css-minification","css-minifier","html-minification","html-minifier","html-minify","js-minification","js-minifier","mini","minifier","minify-css","minify-html","minify-javascript","minify-js","php"],"created_at":"2024-12-22T18:19:47.197Z","updated_at":"2025-04-09T04:11:53.843Z","avatar_url":"https://github.com/codyverse.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e # UKRAINE NEEDS YOUR HELP NOW!\n\u003e\n\u003e On 24 February 2022, Russian [President Vladimir Putin ordered an invasion of Ukraine by Russian Armed Forces](https://www.bbc.com/news/world-europe-60504334).\n\u003e\n\u003e Your support is urgently needed.\n\u003e\n\u003e - Donate to the volunteers. Here is the volunteer fund helping the Ukrainian army to provide all the necessary equipment:\n\u003e  https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zboru-koshtiv-na-potrebi-armiyi or https://savelife.in.ua/en/donate/\n\u003e - Triple-check social media sources. Russian disinformation is attempting to coverup and distort the reality in Ukraine.\n\u003e - Help Ukrainian refugees who are fleeing Russian attacks and shellings: https://www.globalcitizen.org/en/content/ways-to-help-ukraine-conflict/\n\u003e - Put pressure on your political representatives to provide help to Ukraine.\n\u003e - Believe in the Ukrainian people, they will not surrender, they don't have another Ukraine.\n\u003e\n\u003e THANK YOU!\n----\n\n# ShrinkWrap\n\n## Description\n**ShrinkWrap** it's a wrapper for PHP minifiers of HTML/JS/CSS code. The main purpose of creating this wheel is the desire to have a more or less flexible tool for minifying ready-made HTML pages created by 3rd-party applications. Simply put - we submit an HTML page at the input, and at the output we have a page in which (optional):\n - HTML, inline JS-scripts and CSS-styles are minified.\n - JS and CSS files referenced by the page (except external ones) are minified (can also be combined) and cached, and the corresponding links are changed to point to the cache.\n\nAt the moment, **ShrinkWrap** uses the following tools:\n- HTML DOM parser:\n    - [Masterminds/HTML5-PHP](https://github.com/Masterminds/html5-php).\n- Minifiers:\n    - HTML:\n\t    - [voku/HtmlMin](https://github.com/voku/HtmlMin).\n    - JS:\n\t    - [matthiasmullie/minify](https://github.com/matthiasmullie/minify).\n    - CSS:\n\t    - [matthiasmullie/minify](https://github.com/matthiasmullie/minify).\n\n## Requirments\n- `PHP \u003e= 7.3.0`\n\n## Installation\nUse `composer`: `composer require fpvcode/shrinkwrap`.  \nDue to dependency requirements the package loaded by default requires PHP version `8.1.0`. To download the package compatible with PHP `7.3.0`, create a `composer.json` file with the following content:\n```\n{\n    \"config\": {\n        \"vendor-dir\": \"vendor\",\n        \"platform\": {\n            \"php\": \"7.3\"\n        }\n    }\n}\n\n```\n\n## Usage\n```\nuse fpvcode\\ShrinkWrap;\n\n$shrinkwrap = new ShrinkWrap();\n\n// Global options\n$shrinkwrap-\u003edoMinifyHtml(true);        // Allow to minify HTML Code. Default value is `false`.\n$shrinkwrap-\u003edoMinifyInlineJs(true);    // Allow to minify inline scripts. The scripts combine and append in the bottom of related parent tag (`head` or `body`). Default value is `false`.\n$shrinkwrap-\u003edoMinifyInlineCss(true);   // Allow to minify inline styles. The styles combine and append in the bottom of related parent tag (`head` or `body`). Default value is `false`.\n$shrinkwrap-\u003edoMinifyJs(true);          // Allow to minify and cache non-minified JS-files. Default value is `false`.\n$shrinkwrap-\u003edoCombineJs(true);         // Allow to combine all JS-files into one. Depends on `-\u003edoMinifyJS(true)`. Default value is `false`.\n$shrinkwrap-\u003edoMinifyCss(true);         // Allow to minify and cache non-minified JS-files. Default value is `false`.\n$shrinkwrap-\u003edoCombineCss(true);        // Allow to combine all CSS-files into one. Depends on `-\u003edoMinifyCSS(true)`. Default value is `false`.\n$shrinkwrap-\u003edoLog(true);               // Show some info in the browser console. Default value is `false`.\n$shrinkwrap-\u003eassetDir('assets');        // Directory to store minified files cache. Default value is `__DIR__/assets`.\n\n/* --------------------------------------------------------------------------*/\n// Configure minify engines and set their native options.\n/* --------------------------------------------------------------------------*/\n\n// Voku HtmlMin minify options.\n$voku_options = [\n\t'doOptimizeViaHtmlDomParser'                   =\u003e true,  // optimize html via \"HtmlDomParser()\"\n\t'doRemoveComments'                             =\u003e true,  // remove default HTML comments (depends on \"doOptimizeViaHtmlDomParser(true)\")\n\t'doSumUpWhitespace'                            =\u003e true,  // sum-up extra whitespace from the Dom (depends on \"doOptimizeViaHtmlDomParser(true)\")\n\t'doRemoveWhitespaceAroundTags'                 =\u003e true,  // remove whitespace around tags (depends on \"doOptimizeViaHtmlDomParser(true)\")\n\t'doOptimizeAttributes'                         =\u003e true,  // optimize html attributes (depends on \"doOptimizeViaHtmlDomParser(true)\")\n\t'doRemoveHttpPrefixFromAttributes'             =\u003e true,  // remove optional \"http:\"-prefix from attributes (depends on \"doOptimizeAttributes(true)\")\n\t'doRemoveHttpsPrefixFromAttributes'            =\u003e true,  // remove optional \"https:\"-prefix from attributes (depends on \"doOptimizeAttributes(true)\")\n\t'doKeepHttpAndHttpsPrefixOnExternalAttributes' =\u003e true,  // keep \"http:\"- and \"https:\"-prefix for all external links\n\t'doMakeSameDomainsLinksRelative'               =\u003e [],    // make some links relative, by removing the domain from attributes (['example.com'])\n\t'doRemoveDefaultAttributes'                    =\u003e true,  // remove defaults (depends on \"doOptimizeAttributes(true)\" | disabled by default)\n\t'doRemoveDeprecatedAnchorName'                 =\u003e true,  // remove deprecated anchor-jump (depends on \"doOptimizeAttributes(true)\")\n\t'doRemoveDeprecatedScriptCharsetAttribute'     =\u003e true,  // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on \"doOptimizeAttributes(true)\")\n\t'doRemoveDeprecatedTypeFromScriptTag'          =\u003e true,  // remove deprecated script-mime-types (depends on \"doOptimizeAttributes(true)\")\n\t'doRemoveDeprecatedTypeFromStylesheetLink'     =\u003e true,  // remove \"type=text/css\" for css links (depends on \"doOptimizeAttributes(true)\")\n\t'doRemoveDeprecatedTypeFromStyleAndLinkTag'    =\u003e true,  // remove \"type=text/css\" from all links and styles\n\t'doRemoveDefaultMediaTypeFromStyleAndLinkTag'  =\u003e true,  // remove \"media=\"all\" from all links and styles\n\t'doRemoveDefaultTypeFromButton'                =\u003e false, // remove type=\"submit\" from button tags\n\t'doRemoveEmptyAttributes'                      =\u003e true,  // remove some empty attributes (depends on \"doOptimizeAttributes(true)\")\n\t'doRemoveValueFromEmptyInput'                  =\u003e true,  // remove 'value=\"\"' from empty \u003cinput\u003e (depends on \"doOptimizeAttributes(true)\")\n\t'doSortCssClassNames'                          =\u003e true,  // sort css-class-names, for better gzip results (depends on \"doOptimizeAttributes(true)\")\n\t'doSortHtmlAttributes'                         =\u003e true,  // sort html-attributes, for better gzip results (depends on \"doOptimizeAttributes(true)\")\n\t'doRemoveSpacesBetweenTags'                    =\u003e true,  // remove more (aggressive) spaces in the dom (disabled by default)\n\t'doRemoveOmittedQuotes'                        =\u003e true,  // remove quotes e.g. class=\"lall\" =\u003e class=lall\n\t'doRemoveOmittedHtmlTags'                      =\u003e true,  // remove ommitted html tags e.g. \u003cp\u003elall\u003c/p\u003e =\u003e \u003cp\u003elall\n];\n\n$shrinkwrap-\u003ehtmlEngineConfig('voku', $voku_options); // allows to customize the Voku HtmlMin minifier.\n\n$html = '\n\u003c!DOCTYPE html\u003e\n\u003chtml dir=\"ltr\" lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"\u003e\n    \u003ctitle\u003eHTML page\u003c/title\u003e\n\n    \u003cscript\u003e\n      function a() {\n        let a = 0;\n      }\n    \u003c/script\u003e\n\n    \u003cstyle\u003e\n      .class-a {\n        border-radius: 4px;\n      }\n    \u003c/style\u003e\n\n    \u003cscript src=\"https://code.jquery.com/jquery-3.7.1.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n    \u003cscript src=\"js/a.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n    \u003cscript src=\"js/b.min.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n\n    \u003clink href=\"https://cdn.usebootstrap.com/bootstrap/3.3.7/css/bootstrap.css\" rel=\"stylesheet\" media=\"screen\"\u003e\n    \u003clink href=\"css/a.css\" rel=\"stylesheet\" media=\"screen\"\u003e\n    \u003clink href=\"css/b.min.css\" rel=\"stylesheet\" media=\"screen\"\u003e\n  \u003c/head\u003e\n\n  \u003cbody\u003e\n    \u003cdiv\u003e\n      Test HTML\n    \u003c/div\u003e\n\n    \u003c!-- Comment --\u003e\n    \u003cscript\u003e\n      function b() {\n        let b = 0;\n      }\n    \u003c/script\u003e\n\n    \u003cscript\u003e\n      function c() {\n        let c = 0;\n      }\n    \u003c/script\u003e\n\n    \u003c!-- Comment --\u003e\n    \u003cstyle\u003e\n      .class-b {\n        border-radius: 4px;\n      }\n    \u003c/style\u003e\n    \u003cstyle\u003e\n      .class-c {\n        border-radius: 4px;\n      }\n    \u003c/style\u003e\n  \u003c/body\u003e\n\n\n\u003c/html\u003e';\n\n$html = $shrinkwrap-\u003eoutput($html);\n```\nMinified output:\n```\n\u003c!DOCTYPE html\u003e\n\u003chtml dir=\"ltr\" lang=\"en\"\u003e\u003chead\u003e\u003cmeta charset=\"UTF-8\"\u003e\u003cmeta content=\"width=device-width, initial-scale=1\" name=\"viewport\"\u003e\u003cmeta content=\"IE=edge\" http-equiv=\"X-UA-Compatible\"\u003e\u003ctitle\u003eHTML page\u003c/title\u003e\u003cscript src=\"//code.jquery.com/jquery-3.7.1.js\"\u003e\u003c/script\u003e\u003clink href=\"//cdn.usebootstrap.com/bootstrap/3.3.7/css/bootstrap.css\" media=\"screen\" rel=\"stylesheet\"\u003e\u003cscript src=\"assets/4eb126993fd8e08ddf2c186bd95cd514.min.js\"\u003e\u003c/script\u003e\u003clink href=\"assets/55a39d42c37de2a6ca9617f70dfc2bfa.min.css\" rel=\"stylesheet\"\u003e\u003cscript\u003efunction a(){let a=0}\u003c/script\u003e\u003cstyle\u003e.class-a{border-radius:4px}\u003c/style\u003e\u003cbody\u003e\u003cdiv\u003e Test HTML \u003c/div\u003e\u003cscript\u003efunction b(){let b=0};function c(){let c=0}\u003c/script\u003e\u003cstyle\u003e.class-b{border-radius:4px}.class-c{border-radius:4px}\u003c/style\u003e\u003c/body\u003e\u003c/head\u003e\u003c/html\u003e\n```\n\n## Thanks\n- Thanks to [Lars Moelleken](https://github.com/voku) for [HtmlMin](https://github.com/voku/HtmlMin) - HTML Compressor and Minifier for PHP.\n- Thanks to [Matthias Mullie](https://github.com/matthiasmullie) for [Minify](https://github.com/matthiasmullie/minify) - CSS and JavaScript minifier.\n- Thanks to [Masterminds](https://github.com/Masterminds) for [HTML5-PHP](https://github.com/Masterminds/html5-php) - An HTML5 parser and serializer for PHP.\n- Thanks to [Microsoft](https://www.microsoft.com/) for [Visual Studio Code](https://code.visualstudio.com/) and [GitHub](https://github.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodyverse%2Fshrinkwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodyverse%2Fshrinkwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodyverse%2Fshrinkwrap/lists"}