0712-2888027 189-8648-0214
微信公眾號(hào)

孝感風(fēng)信網(wǎng)絡(luò)科技有限公司微信公眾號(hào)

當(dāng)前位置:主頁(yè) > 技術(shù)支持 > PHP > laravel擴(kuò)展包renatomarinho/laravel-page-speed 壓縮HTML加速網(wǎng)頁(yè)響應(yīng)

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

時(shí)間:2018-12-07來源:風(fēng)信官網(wǎng) 點(diǎn)擊: 1211次
壓縮 HTML 加速網(wǎng)頁(yè)響應(yīng)—— renatomarinho/laravel-page-speed,擴(kuò)展包可以自動(dòng)的優(yōu)化網(wǎng)站,將HTML加速輸出顯示在客戶端瀏覽器。
 
項(xiàng)目地址:https://github.com/renatomarinho/laravel-page-speed
 
安裝命令:
 
$ composer require renatomarinho/laravel-page-speed
 
擴(kuò)展包中使用了中間件
 
//app/Http/Kernel.php
 
protected $middleware = [
    ...
    \RenatoMarinho\LaravelPageSpeed\Middleware\InlineCss::class, //轉(zhuǎn)變html中的行內(nèi)樣式
    \RenatoMarinho\LaravelPageSpeed\Middleware\ElideAttributes::class, //去除html中多余的屬性
\RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls::class,  //去除html中所有的協(xié)議部分http或https,
    \RenatoMarinho\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class,  //檢測(cè)html中所有的鏈接,并進(jìn)行預(yù)加載
    \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments::class,  //去除html中所有的注釋信息   
    \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveQuotes::class, //去除html標(biāo)簽中的引號(hào)
    \RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class,  //去除html中所有的換行、空格等信息
]
 
注意:響應(yīng)式中間件的讀取順序是從下向上。
 
我們將中間件注冊(cè)在web,所有通過web訪問的數(shù)據(jù)都可以進(jìn)行壓縮
 
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)頁(yè)響應(yī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',
        ],
    ];

您可能感興趣的相關(guān)文章:

欄目列表
推薦內(nèi)容
熱點(diǎn)內(nèi)容
展開