PHPackages                             uak35/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. uak35/laravel-response-compression

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

uak35/laravel-response-compression
==================================

Laravel response compression middleware

v0.0.9(1mo ago)0225MITPHPPHP ^8.3.0

Since Oct 22Pushed 1mo agoCompare

[ Source](https://github.com/UAK-35/laravel-response-compression)[ Packagist](https://packagist.org/packages/uak35/laravel-response-compression)[ RSS](/packages/uak35-laravel-response-compression/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (18)Versions (10)Used By (0)

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

[](#laravel-response-compression)

[![Latest Stable Version](https://camo.githubusercontent.com/f0265d506dd7c23ddd729fc47a258affa2e308b0f04a6806d1855f8c8b037109/68747470733a2f2f706f7365722e707567782e6f72672f75616b33352f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f76)](https://packagist.org/packages/uak35/laravel-response-compression) [![Total Downloads](https://camo.githubusercontent.com/e76ba5911d60f9a1a72ced2a3fde3d584cdaaee3fccfc7ad010a450ec43c9517/68747470733a2f2f706f7365722e707567782e6f72672f75616b33352f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f646f776e6c6f616473)](https://packagist.org/packages/uak35/laravel-response-compression) [![Latest Unstable Version](https://camo.githubusercontent.com/29473e26f951a71db33837b84fb8571f91cd25049dca3aefc1a293ac3b8c87e6/68747470733a2f2f706f7365722e707567782e6f72672f75616b33352f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f762f756e737461626c65)](https://packagist.org/packages/uak35/laravel-response-compression) [![License](https://camo.githubusercontent.com/a7dfd57a6bce37eaabf133fae5d1059a01a7cd8add28ebdffc34585fafac0a98/68747470733a2f2f706f7365722e707567782e6f72672f75616b33352f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f6c6963656e7365)](https://packagist.org/packages/uak35/laravel-response-compression) [![PHP Version Require](https://camo.githubusercontent.com/b1ab74f8408cffb9e2466620b46d02992e74c01324227ff65946ca71143b281f/68747470733a2f2f706f7365722e707567782e6f72672f75616b33352f6c61726176656c2d726573706f6e73652d636f6d7072657373696f6e2f726571756972652f706870)](https://packagist.org/packages/uak35/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 uak35/laravel-response-compression
```

Publish the configuration file:

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

---

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

[](#middleware-overview)

This package provides the following middleware:

#### Compression Middleware

[](#compression-middleware)

Applies **Gzip**, **Brotli**, or **Zstd** 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.

Note

To use Zstandard (ZSTD) effectively, ensure that the ZSTD PHP extension is properly installed.

---

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: [
        ...
        \Uak35\ResponseCompression\Middleware\CompressResponse::class,
    ]);
})
```

#### Route Middleware

[](#route-middleware)

Alternatively, register it as route middleware for selective application:

```
use Uak35\ResponseCompression\Middleware\CompressResponse;

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

---

Config
------

[](#config)

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

/**
 * Enable or disable the response compression during testing.
 */
'enabled_for_testing' => env('RESPONSE_COMPRESSION_ENABLED_FOR_TESTING', true),

/**
 * The compression algorithm to use. Can be either 'gzip' or 'br' or 'zstd' if br or zstd extension is installed and enabled.
 */
'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),

    'non_supporting_user_agent_prefixes' => [
        'ELB-HealthChecker/',
        'PostmanRuntime/',
        'axios/',
        'Dart/',
    ],
],

'zstd' => [
    /**
     * The level of compression. Can be given as 0 for no compression up to 22
     * for maximum compression. If not given, the default compression level will
     * be the default compression level of the zstd library.
     *
     * @see https://github.com/kjdev/php-ext-zstd
     */
    'level' => env('RESPONSE_COMPRESSION_ZSTD_LEVEL', 3),

    'non_supporting_user_agent_prefixes' => [
        'ELB-HealthChecker/',
        'PostmanRuntime/',
        'axios/',
        'Dart/',
        'IntelliJ HTTP Client/',
    ],
],

'try_multiple_encodings' => env('RESPONSE_COMPRESSION_TRY_MULTIPLE_ENCODINGS', false),

'multiple_encodings_order' => env('RESPONSE_COMPRESSION_MULTIPLE_ENCODINGS_ORDER', 'br,zstd,gzip')
```

---

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/uak35/laravel-response-compression/blob/main/LICENSE) for more information.

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.1% 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 ~24 days

Recently: every ~48 days

Total

9

Last Release

52d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

phplaravelperformanceencodingoptimizeUak35

###  Code Quality

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40140.4k2](/packages/erlandmuchasaj-laravel-gzip)[zidbih/laravel-deadlock

Make temporary Laravel workarounds expire and fail CI when ignored.

984.0k](/packages/zidbih-laravel-deadlock)

PHPackages © 2026

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