netnak/phpinify

v2.0.0 2025-05-27 11:45 UTC

This package is not auto-updated.

Last update: 2025-05-28 09:59:34 UTC


README

Phpinify is a Statamic addon that minifies HTML responses and/or static cached pages using voku/html-min.

🚀 Features

Phpinify wraps the powerful HtmlMin engine and exposes its configuration through a publishable config file. You can toggle the following features:

  • doOptimizeViaHtmlDomParser() – optimize HTML using the DOM parser
  • doRemoveComments() – remove HTML comments
  • doSumUpWhitespace() – collapse excess whitespace
  • doRemoveWhitespaceAroundTags() – trim whitespace around tags
  • doOptimizeAttributes() – optimize HTML attributes
  • doRemoveHttpPrefixFromAttributes() – strip http: from attributes
  • doRemoveHttpsPrefixFromAttributes() – strip https: from attributes
  • doKeepHttpAndHttpsPrefixOnExternalAttributes() – preserve prefixes for external links
  • doMakeSameDomainsLinksRelative(['example.com']) – make internal links relative
  • doRemoveDefaultAttributes() – remove default attribute values
  • doRemoveDeprecatedAnchorName() – remove deprecated anchor name attributes
  • doRemoveDeprecatedScriptCharsetAttribute() – remove charset from <script> tags
  • doRemoveDeprecatedTypeFromScriptTag() – remove deprecated type from <script>
  • doRemoveDeprecatedTypeFromStylesheetLink() – remove type="text/css" from CSS links
  • doRemoveDeprecatedTypeFromStyleAndLinkTag() – remove type="text/css" globally
  • doRemoveDefaultMediaTypeFromStyleAndLinkTag() – remove media="all"
  • doRemoveDefaultTypeFromButton() – remove type="submit" from buttons
  • doRemoveEmptyAttributes() – strip empty attributes
  • doRemoveValueFromEmptyInput() – remove value="" from empty inputs
  • doSortCssClassNames() – sort class names for better Gzip performance
  • doSortHtmlAttributes() – sort attributes for better Gzip performance
  • doRemoveSpacesBetweenTags() – aggressively trim inter-tag spaces
  • doRemoveOmittedQuotes() – omit unnecessary attribute quotes
  • doRemoveOmittedHtmlTags() – omit redundant HTML tags

📦 Installation

Install via Composer:

composer require netnak/phpinify

Then publish the config file (optional):

php artisan vendor:publish --tag=phpinify-config --force

⚙️ Configuration

Phpinify auto-registers itself.

To manually ensure it's added as a static caching replacer, edit config/statamic/static_caching.php:

'replacers' => [
    // ...
    \Netnak\Phpinify\Replacers\PhpinifyReplacer::class,
],

✅ Usage

Enable minification via your .env file:

PHPINIFY_RESPONSE=true
PHPINIFY_STATIC=true

These values toggle options in config/phpinify.php:

'enable_response_minifier' => env('PHPINIFY_RESPONSE', false),
'enable_static_cache_replacer' => env('PHPINIFY_STATIC', false),

Exclude paths from minification with:

'ignored_paths' => ['!/*', 'api/*'],

🪪 License

MIT — see the LICENSE file for details.