PHPackages                             fpvcode/shrinkwrap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fpvcode/shrinkwrap

ActiveProject[Utility &amp; Helpers](/categories/utility)

fpvcode/shrinkwrap
==================

All-in-one HTML/JS/CSS code minifier.

v0.0.4(2y ago)016MITPHPPHP &gt;=7.3

Since Nov 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/fpvcode/shrinkwrap)[ Packagist](https://packagist.org/packages/fpvcode/shrinkwrap)[ Docs](https://github.com/fpvcode/shrinkwrap)[ RSS](/packages/fpvcode-shrinkwrap/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

> # UKRAINE NEEDS YOUR HELP NOW!
>
> [](#ukraine-needs-your-help-now)
>
> 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).
>
> Your support is urgently needed.
>
> - Donate to the volunteers. Here is the volunteer fund helping the Ukrainian army to provide all the necessary equipment:  or
> - Triple-check social media sources. Russian disinformation is attempting to coverup and distort the reality in Ukraine.
> - Help Ukrainian refugees who are fleeing Russian attacks and shellings:
> - Put pressure on your political representatives to provide help to Ukraine.
> - Believe in the Ukrainian people, they will not surrender, they don't have another Ukraine.
>
> THANK YOU!

---

ShrinkWrap
==========

[](#shrinkwrap)

Description
-----------

[](#description)

**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):

- HTML, inline JS-scripts and CSS-styles are minified.
- 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.

At the moment, **ShrinkWrap** uses the following tools:

- HTML DOM parser:
    - [Masterminds/HTML5-PHP](https://github.com/Masterminds/html5-php).
- Minifiers:
    - HTML:
        - [voku/HtmlMin](https://github.com/voku/HtmlMin).
    - JS:
        - [matthiasmullie/minify](https://github.com/matthiasmullie/minify).
    - CSS:
        - [matthiasmullie/minify](https://github.com/matthiasmullie/minify).

Requirments
-----------

[](#requirments)

- `PHP >= 7.3.0`

Installation
------------

[](#installation)

Use `composer`: `composer require fpvcode/shrinkwrap`.
Due 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:

```
{
    "config": {
        "vendor-dir": "vendor",
        "platform": {
            "php": "7.3"
        }
    }
}

```

Usage
-----

[](#usage)

```
use fpvcode\ShrinkWrap;

$shrinkwrap = new ShrinkWrap();

// Global options
$shrinkwrap->doMinifyHtml(true);        // Allow to minify HTML Code. Default value is `false`.
$shrinkwrap->doMinifyInlineJs(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`.
$shrinkwrap->doMinifyInlineCss(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`.
$shrinkwrap->doMinifyJs(true);          // Allow to minify and cache non-minified JS-files. Default value is `false`.
$shrinkwrap->doCombineJs(true);         // Allow to combine all JS-files into one. Depends on `->doMinifyJS(true)`. Default value is `false`.
$shrinkwrap->doMinifyCss(true);         // Allow to minify and cache non-minified JS-files. Default value is `false`.
$shrinkwrap->doCombineCss(true);        // Allow to combine all CSS-files into one. Depends on `->doMinifyCSS(true)`. Default value is `false`.
$shrinkwrap->doLog(true);               // Show some info in the browser console. Default value is `false`.
$shrinkwrap->assetDir('assets');        // Directory to store minified files cache. Default value is `__DIR__/assets`.

/* --------------------------------------------------------------------------*/
// Configure minify engines and set their native options.
/* --------------------------------------------------------------------------*/

// Voku HtmlMin minify options.
$voku_options = [
	'doOptimizeViaHtmlDomParser'                   => true,  // optimize html via "HtmlDomParser()"
	'doRemoveComments'                             => true,  // remove default HTML comments (depends on "doOptimizeViaHtmlDomParser(true)")
	'doSumUpWhitespace'                            => true,  // sum-up extra whitespace from the Dom (depends on "doOptimizeViaHtmlDomParser(true)")
	'doRemoveWhitespaceAroundTags'                 => true,  // remove whitespace around tags (depends on "doOptimizeViaHtmlDomParser(true)")
	'doOptimizeAttributes'                         => true,  // optimize html attributes (depends on "doOptimizeViaHtmlDomParser(true)")
	'doRemoveHttpPrefixFromAttributes'             => true,  // remove optional "http:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
	'doRemoveHttpsPrefixFromAttributes'            => true,  // remove optional "https:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
	'doKeepHttpAndHttpsPrefixOnExternalAttributes' => true,  // keep "http:"- and "https:"-prefix for all external links
	'doMakeSameDomainsLinksRelative'               => [],    // make some links relative, by removing the domain from attributes (['example.com'])
	'doRemoveDefaultAttributes'                    => true,  // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default)
	'doRemoveDeprecatedAnchorName'                 => true,  // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedScriptCharsetAttribute'     => true,  // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedTypeFromScriptTag'          => true,  // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedTypeFromStylesheetLink'     => true,  // remove "type=text/css" for css links (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedTypeFromStyleAndLinkTag'    => true,  // remove "type=text/css" from all links and styles
	'doRemoveDefaultMediaTypeFromStyleAndLinkTag'  => true,  // remove "media="all" from all links and styles
	'doRemoveDefaultTypeFromButton'                => false, // remove type="submit" from button tags
	'doRemoveEmptyAttributes'                      => true,  // remove some empty attributes (depends on "doOptimizeAttributes(true)")
	'doRemoveValueFromEmptyInput'                  => true,  // remove 'value=""' from empty  (depends on "doOptimizeAttributes(true)")
	'doSortCssClassNames'                          => true,  // sort css-class-names, for better gzip results (depends on "doOptimizeAttributes(true)")
	'doSortHtmlAttributes'                         => true,  // sort html-attributes, for better gzip results (depends on "doOptimizeAttributes(true)")
	'doRemoveSpacesBetweenTags'                    => true,  // remove more (aggressive) spaces in the dom (disabled by default)
	'doRemoveOmittedQuotes'                        => true,  // remove quotes e.g. class="lall" => class=lall
	'doRemoveOmittedHtmlTags'                      => true,  // remove ommitted html tags e.g. lall => lall
];

$shrinkwrap->htmlEngineConfig('voku', $voku_options); // allows to customize the Voku HtmlMin minifier.

$html = '

    HTML page

      function a() {
        let a = 0;
      }

      .class-a {
        border-radius: 4px;
      }

      Test HTML

      function b() {
        let b = 0;
      }

      function c() {
        let c = 0;
      }

      .class-b {
        border-radius: 4px;
      }

      .class-c {
        border-radius: 4px;
      }

';

$html = $shrinkwrap->output($html);

```

Minified output:

```

HTML pagefunction a(){let a=0}.class-a{border-radius:4px} Test HTML function b(){let b=0};function c(){let c=0}.class-b{border-radius:4px}.class-c{border-radius:4px}

```

Thanks
------

[](#thanks)

- Thanks to [Lars Moelleken](https://github.com/voku) for [HtmlMin](https://github.com/voku/HtmlMin) - HTML Compressor and Minifier for PHP.
- Thanks to [Matthias Mullie](https://github.com/matthiasmullie) for [Minify](https://github.com/matthiasmullie/minify) - CSS and JavaScript minifier.
- Thanks to [Masterminds](https://github.com/Masterminds) for [HTML5-PHP](https://github.com/Masterminds/html5-php) - An HTML5 parser and serializer for PHP.
- Thanks to [Microsoft](https://www.microsoft.com/) for [Visual Studio Code](https://code.visualstudio.com/) and [GitHub](https://github.com).

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

4

Last Release

860d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/98a2270632bc69059dcf83c1d5def7c8fc29cdec1006df91f3120fca411b3d0b?d=identicon)[anykeyist](/maintainers/anykeyist)

---

Top Contributors

[![anykeyist](https://avatars.githubusercontent.com/u/10338746?v=4)](https://github.com/anykeyist "anykeyist (5 commits)")

---

Tags

css-minificationcss-minifierhtml-minificationhtml-minifierhtml-minifyjs-minificationjs-minifierminiminifierminify-cssminify-htmlminify-javascriptminify-jsphpminifyminifierHTML minifycss minifyjs minifyPHP HTML minifier

### Embed Badge

![Health badge](/badges/fpvcode-shrinkwrap/health.svg)

```
[![Health](https://phpackages.com/badges/fpvcode-shrinkwrap/health.svg)](https://phpackages.com/packages/fpvcode-shrinkwrap)
```

###  Alternatives

[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[tedivm/jshrink

Javascript Minifier built in PHP

76037.7M139](/packages/tedivm-jshrink)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

5694.9k1](/packages/sensiolabs-minify-bundle)[pfaciana/tiny-html-minifier

Minify HTML in PHP with just a single class

1095.9k4](/packages/pfaciana-tiny-html-minifier)[bissolli/php-css-js-minifier

A PHP Class to merge and minify CSS and JavaScript files.

102.8k4](/packages/bissolli-php-css-js-minifier)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
