在laravel项目中压缩响应中间件推荐:CompressResponseContent、LaraOutPress

2023-06-01 00:00:00 响应 中间件 压缩

这是简单地压缩你的Larvel应用程序的最终版本并提供给浏览器的压缩响应内容的laraval中间件.

CompressResponseContent中间件相关链接:

https://github.com/guanguans/laravel-skeleton/blob/master/app/Http/Middleware/CompressResponseContent.php


LaraOutPress (Laravel Output Press)链接:

https://github.com/vrkansagara/LaraOutPress


使用:

<?php

use App\Http\Middleware\CompressResponseContent;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

// CompressResponseContent::skipWhen(function (Request $request){
//     return $request->is('api/*');
// });
//
// CompressResponseContent::mergeReplacementRules([...]); // 合并替换规则

Route::get('/', function (){
    return view('welcome');
})->middleware(sprintf('%s:1', CompressResponseContent::class));


效果截图:

1.png

相关文章