PHPackages                             chr15k/laravel-response-compression - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chr15k/laravel-response-compression

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chr15k/laravel-response-compression
===================================

Laravel response compression middleware

0.2.0(8mo ago)31.3k↓21.4%2MITPHPPHP ^8.2.0CI passing

Since Dec 29Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/chr15k/laravel-response-compression)[ Packagist](https://packagist.org/packages/chr15k/laravel-response-compression)[ RSS](/packages/chr15k-laravel-response-compression/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (3)Used By (0)

Laravel Response Compression
============================

[](#laravel-response-compression)

[![Latest Stable Version](https://camo.githubusercontent.com/7a2d617e97d1db55188a95e2f133fc1e6e2c689c6485acf65624be6835b22a77/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f76)](https://packagist.org/packages/chr15k/laravel-response-compression) [![Total Downloads](https://camo.githubusercontent.com/8aaa6fc694bd6581527e495df0ce1fe4f8052e2ad46690f3d946b8d0f95417f5/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f646f776e6c6f616473)](https://packagist.org/packages/chr15k/laravel-response-compression) [![Latest Unstable Version](https://camo.githubusercontent.com/2c43801ca1d09b3307f1ba4d79462e03a2fa1689f2da618a7b45865c49217bac/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f762f756e737461626c65)](https://packagist.org/packages/chr15k/laravel-response-compression) [![License](https://camo.githubusercontent.com/80e4ab41e01c1062748c091e4a6184f267ac7ea9a920ac64b0d6877b1ba119ef/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f6c6963656e7365)](https://packagist.org/packages/chr15k/laravel-response-compression) [![PHP Version Require](https://camo.githubusercontent.com/391a9f95597b174d2165d8127c800b849de7e3e22869465b022125f2849481dd/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f726571756972652f706870)](https://packagist.org/packages/chr15k/laravel-response-compression)

Boost your Laravel application's performance by optimizing HTTP responses with middleware for compression.

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require chr15k/laravel-response-compression
```

Publish the configuration file:

```
php artisan vendor:publish --provider="Chr15k\ResponseCompression\ResponseCompressionServiceProvider"
```

---

Middleware Overview
-------------------

[](#middleware-overview)

This package provides the following middleware:

#### Compression Middleware

[](#compression-middleware)

Applies **Gzip** or **Brotli** compression to HTTP responses based on client support. This reduces the size of the response payload and enhances load times.

**Ideal For**: Large JSON responses, static files, or data-intensive endpoints.

Note

To use Brotli effectively, ensure that the Brotli PHP extension is properly installed.

Warning

When using Brotli, a client-side decoding error may occur with non-secure connections, as modern browsers generally support Brotli compression only over HTTPS.

---

Setup
-----

[](#setup)

### Register Middleware

[](#register-middleware)

#### Global Middleware

[](#global-middleware)

Apply the middleware globally to all requests:

```
// bootstrap/app.php

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

#### Route Middleware

[](#route-middleware)

Alternatively, register it as route middleware for selective application:

```
use Chr15k\ResponseCompression\Middleware\CompressResponse;

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

---

Config
------

[](#config)

```
/**
 * 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),
]
```

---

Testing
-------

[](#testing)

```
composer test
```

---

Contributing
------------

[](#contributing)

Contributions are welcome! Submit a pull request or open an issue to discuss new features or improvements.

---

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/chr15k/laravel-response-compression/blob/main/LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance60

Regular maintenance activity

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~254 days

Total

2

Last Release

251d ago

PHP version history (2 changes)0.1.1PHP ^8.3.0

0.2.0PHP ^8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c817e814df42c78ac76505c9394a786946a0d9517b64984eca34b6f04010df95?d=identicon)[chr15k](/maintainers/chr15k)

---

Top Contributors

[![chr15k](https://avatars.githubusercontent.com/u/67823070?v=4)](https://github.com/chr15k "chr15k (27 commits)")[![botnetdobbs](https://avatars.githubusercontent.com/u/35170812?v=4)](https://github.com/botnetdobbs "botnetdobbs (1 commits)")

---

Tags

phplaravelperformanceencodingoptimizechr15k

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chr15k-laravel-response-compression/health.svg)

```
[![Health](https://phpackages.com/badges/chr15k-laravel-response-compression/health.svg)](https://phpackages.com/packages/chr15k-laravel-response-compression)
```

###  Alternatives

[monicahq/laravel-cloudflare

Add Cloudflare ip addresses to trusted proxies for Laravel.

3372.7M4](/packages/monicahq-laravel-cloudflare)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[kra8/laravel-snowflake

Snowflake for Laravel and Lumen.

188402.3k6](/packages/kra8-laravel-snowflake)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[datomatic/nova-enum-field

A Laravel Nova PHP 8.1 enum field with filters

20134.2k](/packages/datomatic-nova-enum-field)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
