shemshad/laravel-blade-minify-plus
Composer 安装命令:
composer require shemshad/laravel-blade-minify-plus
包简介
Minify final Laravel Blade HTML safely with first-class Laravel 8-13 support and beginner-friendly configuration.
README 文档
README
laravel-blade-minify-plus is a lightweight package that minifies the final HTML output of Blade views.
It is designed to be easy for beginners and stable for production projects.
Why use this package?
- Reduces HTML size by removing unnecessary whitespace/comments.
- Keeps Blade templates unchanged (works at the response layer).
- Safe defaults that avoid aggressive transformations.
- Supports Laravel 8, 9, 10, 11, 12, and 13.
Requirements
- PHP 8.1+
- Laravel 8.x – 13.x
Installation
composer require shemshad/laravel-blade-minify-plus
Laravel auto-discovers the service provider. If auto-discovery is disabled, register it manually:
// config/app.php 'providers' => [ // ... BladeMinifyPlus\BladeMinifyPlusServiceProvider::class, ],
Quick Start (2 minutes)
- Publish config:
php artisan vendor:publish --tag=blade-minify-plus-config
- Add middleware to route(s):
use Illuminate\Support\Facades\Route; Route::view('/about', 'about')->middleware('minify');
- Open your page and inspect the response HTML.
Laravel version setup
Laravel 11, 12, and 13 (bootstrap/app.php)
Use middleware aliases in bootstrap/app.php:
use BladeMinifyPlus\Middleware\MinifyHtmlMiddleware; use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', ) ->withMiddleware(function (Middleware $middleware) { $middleware->alias([ 'minify' => MinifyHtmlMiddleware::class, ]); // Optional: apply to all web routes. // $middleware->appendToGroup('web', MinifyHtmlMiddleware::class); }) ->create();
A full example is available in:
examples/bootstrap.app.l12.phpexamples/bootstrap.app.l13.php
Laravel 10 and earlier (Kernel)
Register middleware alias in app/Http/Kernel.php:
protected $middlewareAliases = [ // ... 'minify' => \BladeMinifyPlus\Middleware\MinifyHtmlMiddleware::class, ];
For older app skeletons, use $routeMiddleware instead of $middlewareAliases.
Configuration
After publishing, edit config/blade-minify-plus.php.
Main options
enabled(bool): Global on/off switch.skip_routes(array): Route names that should not be minified.options(array): Low-levelvoku/html-minflags.
Example
return [ 'enabled' => env('BLADE_MINIFY_PLUS_ENABLED', true), 'skip_routes' => [ 'api.docs', 'webhooks.receive', ], 'options' => [ 'doRemoveComments' => true, 'doSumUpWhitespace' => true, ], ];
How compatibility is preserved across Laravel versions
This package keeps compatibility by:
- Registering only a middleware alias in the service provider.
- Avoiding hard coupling to app-kernel internals.
- Minifying only eligible HTML responses.
- Skipping streamed/file responses and non-HTML content types.
This means Laravel 13 support is added without breaking Laravel 8-12 behavior.
Tips for beginners
- Start with route-level middleware first (
->middleware('minify')). - Test a few pages before enabling globally.
- Keep advanced
optionsat defaults unless you need deeper optimization. - If a page behaves unexpectedly, add its route name to
skip_routes.
Development checks
php -l src/BladeMinifyPlusServiceProvider.php php -l src/Middleware/MinifyHtmlMiddleware.php php -l config/blade-minify-plus.php
License
MIT
shemshad/laravel-blade-minify-plus 适用场景与选型建议
shemshad/laravel-blade-minify-plus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.4k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「html」 「minify」 「middleware」 「laravel」 「blade」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shemshad/laravel-blade-minify-plus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shemshad/laravel-blade-minify-plus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shemshad/laravel-blade-minify-plus 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
Caching and compression for Twig assets (JavaScript and CSS).
CSS & JavaScript minifier for Silverstripe
A package for pack css and javascript files
统计信息
- 总下载量: 2.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-21