PHP code example of chr15k / laravel-response-compression

1. Go to this page and download the library: Download chr15k/laravel-response-compression library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chr15k / laravel-response-compression example snippets


// bootstrap/app.php

->withMiddleware(function (Middleware $middleware) {
    ...
    $middleware->web(append: [
        ...
        \Chr15k\ResponseCompression\Middleware\CompressResponse::class,
    ]);
})

use Chr15k\ResponseCompression\Middleware\CompressResponse;

Route::get('/profile', function () {
    // ...
})->middleware(CompressResponse::class);

/**
 * Enable or disable the response compression.
 */
'enabled' => env('RESPONSE_COMPRESSION_ENABLED', true),

/**
 * The compression algorithm to use. Can be either 'gzip' or 'br'.
 */
'algorithm' => env('RESPONSE_COMPRESSION_ALGORITHM', 'gzip'),

/**
 * The minimum length of the response content to be compressed.
 */
'min_length' => env('RESPONSE_COMPRESSION_MIN_LENGTH', 1024),

'gzip' => [
    /**
     * The level of compression. Can be given as 0 for no compression up to 9
     * for maximum compression. If not given, the default compression level will
     * be the default compression level of the zlib library.
     *
     * @see https://www.php.net/manual/en/function.gzencode.php
     */
    'level' => env('RESPONSE_COMPRESSION_GZIP_LEVEL', 5),
],

'br' => [
    /**
     * The level of compression. Can be given as 0 for no compression up to 11
     * for maximum compression. If not given, the default compression level will
     * be the default compression level of the brotli library.
     *
     * @see https://www.php.net/manual/en/function.brotli-compress.php
     */
    'level' => env('RESPONSE_COMPRESSION_BROTLI_LEVEL', 5),
]
bash
php artisan vendor:publish --provider="Chr15k\ResponseCompression\ResponseCompressionServiceProvider"