netnak / phpinify
v2.0.0
2025-05-27 11:45 UTC
Requires
- statamic/cms: ^4.0 || ^5.0
- voku/html-min: ^4.4
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 parserdoRemoveComments()
– remove HTML commentsdoSumUpWhitespace()
– collapse excess whitespacedoRemoveWhitespaceAroundTags()
– trim whitespace around tagsdoOptimizeAttributes()
– optimize HTML attributesdoRemoveHttpPrefixFromAttributes()
– striphttp:
from attributesdoRemoveHttpsPrefixFromAttributes()
– striphttps:
from attributesdoKeepHttpAndHttpsPrefixOnExternalAttributes()
– preserve prefixes for external linksdoMakeSameDomainsLinksRelative(['example.com'])
– make internal links relativedoRemoveDefaultAttributes()
– remove default attribute valuesdoRemoveDeprecatedAnchorName()
– remove deprecated anchor name attributesdoRemoveDeprecatedScriptCharsetAttribute()
– remove charset from<script>
tagsdoRemoveDeprecatedTypeFromScriptTag()
– remove deprecated type from<script>
doRemoveDeprecatedTypeFromStylesheetLink()
– removetype="text/css"
from CSS linksdoRemoveDeprecatedTypeFromStyleAndLinkTag()
– removetype="text/css"
globallydoRemoveDefaultMediaTypeFromStyleAndLinkTag()
– removemedia="all"
doRemoveDefaultTypeFromButton()
– removetype="submit"
from buttonsdoRemoveEmptyAttributes()
– strip empty attributesdoRemoveValueFromEmptyInput()
– removevalue=""
from empty inputsdoSortCssClassNames()
– sort class names for better Gzip performancedoSortHtmlAttributes()
– sort attributes for better Gzip performancedoRemoveSpacesBetweenTags()
– aggressively trim inter-tag spacesdoRemoveOmittedQuotes()
– omit unnecessary attribute quotesdoRemoveOmittedHtmlTags()
– 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.