Minimatic is a Statamic addon that minifies HTML responses and/or static cached pages using
voku/html-min
.
π Features
Minimatic 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/minimatic
Then publish the config file (optional):
php artisan vendor:publish --tag=minimatic-config --force
βοΈ Configuration
Minimatic auto-registers its own replacer at runtime.
However, if you want to manually ensure it's added as a static caching replacer, edit config/statamic/static_caching.php
:
'replacers' => [ // ... \Netnak\Minimatic\Replacers\MinimaticReplacer::class,],
β Usage
Enable minification via your .env
file:
MINIFY_RESPONSE=trueMINIFY_STATIC=true
These values toggle options in config/minimatic.php
:
'enable_response_minifier' => env('MINIFY_RESPONSE', false),'enable_static_cache_replacer' => env('MINIFY_STATIC', false),
Exclude paths from minification with:
'ignored_paths' => ['!/*', 'api/*'],
πͺͺ License
MIT β see the LICENSE file for details.