承接 shemshad/laravel-blade-minify-plus 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shemshad/laravel-blade-minify-plus

最新稳定版本:v1.2.0

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)

  1. Publish config:
php artisan vendor:publish --tag=blade-minify-plus-config
  1. Add middleware to route(s):
use Illuminate\Support\Facades\Route;

Route::view('/about', 'about')->middleware('minify');
  1. 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.php
  • examples/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-level voku/html-min flags.

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 options at 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

统计信息

  • 总下载量: 1.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固