0712-2888027 189-8648-0214
微信公眾號

孝感風信網(wǎng)絡科技有限公司微信公眾號

當前位置:主頁 > 技術支持 > PHP > laravel擴展包renatomarinho/laravel-page-speed 壓縮HTML加速網(wǎng)頁響應

laravel擴展包renatomarinho/laravel-page-speed 壓縮HTML加速網(wǎng)頁響應

時間:2018-12-07來源:風信官網(wǎng) 點擊: 1211次
壓縮 HTML 加速網(wǎng)頁響應—— renatomarinho/laravel-page-speed,擴展包可以自動的優(yōu)化網(wǎng)站,將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中所有的協(xié)議部分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訪問的數(shù)據(jù)都可以進行壓縮
 
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 加速網(wǎng)頁響應—— 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',
        ],
    ];
欄目列表
推薦內容
熱點內容
展開