0712-2888027 189-8648-0214
微信公众号

孝感风信网络科技有限公司微信公众号

当前位置: 主页 > 技术支持 > PHP > laravel扩展包renatomarinho/laravel-page-speed 压缩HTML加速网页响应

laravel扩展包renatomarinho/laravel-page-speed 压缩HTML加速网页响应

时间:2018-12-07来源:风信网 点击:
压缩 HTML 加速网页响应—— renatomarinho/laravel-page-speed,扩展包可以自动的优化网站,将HTML加速输出显示在客户端浏览器。
 
项目地址:https://github.com/renatomarinho/laravel-page-speed
 
安装命令:
 
$ composer require renatomarinho/laravel-page-speed
 
扩展包中使用了中间件
 
//app/Http/Kernel.php
 
protected $middleware = [
    ...
    \RenatoMarinho\LaravelPageSpeed\Middleware\InlineCss::class, //转变html中的行内样式
    \RenatoMarinho\LaravelPageSpeed\Middleware\ElideAttributes::class, //去除html中多余的属性
\RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls::class,  //去除html中所有的协议部分http或https,
    \RenatoMarinho\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class,  //检测html中所有的链接,并进行预加载
    \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments::class,  //去除html中所有的注释信息   
    \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveQuotes::class, //去除html标签中的引号
    \RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class,  //去除html中所有的换行、空格等信息
]
 
注意:响应式中间件的读取顺序是从下向上。
 
我们将中间件注册在web,所有通过web访问的数据都可以进行压缩
 
protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
 
            //压缩 HTML 加速网页响应—— renatomarinho/laravel-page-speed
            \RenatoMarinho\LaravelPageSpeed\Middleware\InlineCss::class,
            \RenatoMarinho\LaravelPageSpeed\Middleware\ElideAttributes::class,
\RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls::class,
            \RenatoMarinho\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class,
            \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments::class,            
            \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveQuotes::class,
            \RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class,
        ],
 
        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];
栏目列表
推荐内容
热点内容
展开