el-schneider / statamic-html-minify
An addon to minify HTML for Statamic v5
Fund package maintenance!
el-schneider
Requires
- php: ^8.2
- statamic/cms: ^5.0
- voku/html-min: ^4.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^7.0|^8.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.0
- phpunit/phpunit: ^10.0
- spatie/pest-plugin-snapshots: ^2.0
README
A modern HTML minification addon for Statamic v5 that automatically compresses your website's HTML output, reducing page load times and bandwidth usage.
Features
- Automatic HTML Minification: Compresses HTML on every request via middleware
- Statamic v5 Compatible: Fully modernized for the latest Statamic version
- Performance Optimized: Cached minification engine for optimal performance
- Developer Friendly: Skip minification in debug mode during development
- Highly Configurable: Comprehensive configuration with environment variable support
- Error Resilient: Graceful fallback if minification fails
- Production Ready: Battle-tested with comprehensive test suite
Installation
Install the addon via Composer:
composer require el-schneider/statamic-html-minify
Publish the configuration file:
php artisan vendor:publish --provider="ElSchneider\HtmlMinify\HtmlMinifyServiceProvider"
Configuration
The addon provides extensive configuration options via config/html-minify.php
:
return [ // Enable/disable minification entirely 'enabled' => env('HTML_MINIFY_ENABLED', true), // Skip minification when APP_DEBUG is true 'skip_on_debug' => env('HTML_MINIFY_SKIP_ON_DEBUG', false), // Minification options 'removeComments' => env('HTML_MINIFY_REMOVE_COMMENTS', true), 'sumUpWhitespace' => env('HTML_MINIFY_SUM_UP_WHITESPACE', true), 'removeSpacesBetweenTags' => env('HTML_MINIFY_REMOVE_SPACES_BETWEEN_TAGS', true), // ... and many more options ];
Environment Variables
All configuration options support environment variables for easy deployment:
HTML_MINIFY_ENABLED=true HTML_MINIFY_SKIP_ON_DEBUG=true HTML_MINIFY_REMOVE_COMMENTS=true
Documentation
For detailed configuration options and advanced usage, see the DOCUMENTATION.md.
Requirements
- PHP 8.2+
- Statamic v5.0+
- Laravel 10/11
Testing
Run the test suite:
vendor/bin/pest
Credits
This addon is maintained by el-schneider and builds upon the original work by:
- Vaggelis Yfantis - Original author and creator
- All Contributors
Big thanks to Vaggelis for creating this addon and sharing it with the community! 🙏
License
The MIT License (MIT). Please see License File for more information.