PHPackages                             erlandmuchasaj/laravel-gzip - 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. erlandmuchasaj/laravel-gzip

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

erlandmuchasaj/laravel-gzip
===========================

Gzip your responses.

1.3.0(1mo ago)40146.5k↓15.2%8[1 issues](https://github.com/erlandmuchasaj/laravel-gzip/issues)2MITPHPPHP ^8.0

Since Jul 26Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/erlandmuchasaj/laravel-gzip)[ Packagist](https://packagist.org/packages/erlandmuchasaj/laravel-gzip)[ Docs](https://github.com/erlandmuchasaj/laravel-gzip)[ Fund](https://ko-fi.com/erlandmuchasaj)[ Fund](https://paypal.me/emcms?country.x=AL&locale.x=en_US)[ RSS](/packages/erlandmuchasaj-laravel-gzip/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (27)Versions (21)Used By (2)

Laravel Gzip
============

[](#laravel-gzip)

Laravel Gzip is a simple and effective way to gzip your response for a better performance.

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

[](#installation)

### Installing the Package

[](#installing-the-package)

You can install the package via composer:

```
composer require erlandmuchasaj/laravel-gzip
```

### Installing Brotli Extension (Optional but Recommended)

[](#installing-brotli-extension-optional-but-recommended)

Brotli provides 15-20% better compression than Gzip and is supported by all modern browsers. To install the Brotli extension, you can use PECL:

#### macOS (using Homebrew):

[](#macos-using-homebrew)

```
pecl install brotli
```

#### Ubuntu/Debian:

[](#ubuntudebian)

```
sudo apt-get install php-brotli
# or
sudo pecl install brotli
```

Note

If Brotli is not available, the package will automatically fall back to Gzip compression.

Config file
-----------

[](#config-file)

Publish the configuration file using artisan.

```
php artisan vendor:publish --provider="ErlandMuchasaj\LaravelGzip\GzipServiceProvider"
```

Usage
-----

[](#usage)

This package has a very easy and straight-forward usage.

### Laravel v11+

[](#laravel-v11)

Just add the middleware in `bootstrap/app.php`, like so:

```
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        // ...
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(\ErlandMuchasaj\LaravelGzip\Middleware\GzipEncodeResponse::class);
    })
    // ...
```

### Laravel v10 and older

[](#laravel-v10-and-older)

Just add the middleware to the `$middleware` array in `app/Http/Kernel.php` like so:

```
/**
 * The application's global HTTP middleware stack.
 *
 * These middleware are run during every request to your application.
 *
 * @var array
 */
protected $middleware = [
    \ErlandMuchasaj\LaravelGzip\Middleware\GzipEncodeResponse::class,
    //...
];
```

Important

In a previous version, we recommended adding the middleware to the `web` middleware group. **Now**, we recommend adding to global `$middleware` because we want to apply gzip to all requests. Additionally, registering the middleware in the `web` group caused debugger to break.

**Also**, if you are using `spatie/laravel-cookie-consent` package, you should register this middleware before the `\Spatie\CookieConsent\CookieConsentMiddleware::class` middleware.

> \[!PS\] To see the package working in production-like mode, use `APP_ENV=production` (double-check typos) and `APP_DEBUG=false`.

### Important for Laravel v11+ / v12

[](#important-for-laravel-v11--v12)

If compression does not apply after changing environment/config values, clear cached config:

```
php artisan optimize:clear
```

When testing locally you can force compression:

```
GZIP_FORCE=true
```

That's it! Now your responses will be gzipped.

Troubleshooting
---------------

[](#troubleshooting)

If you still don't see `Content-Encoding: gzip` or `Content-Encoding: br`, check:

1. The request includes `Accept-Encoding: gzip` (or `br`).
2. Response content is larger than `GZIP_MIN_LENGTH` (default is `256`).
3. Route/path is not excluded by `excluded_paths`.
4. MIME type is compressible.
5. Config cache is cleared (`php artisan optimize:clear`) after env changes.

Benchmark
---------

[](#benchmark)

I tested this package with a fresh installed laravel in homepage and got:

`No Gzip => 72.9kb`

`With Gzip => 19.2kb *`

---

Support me
----------

[](#support-me)

I invest a lot of time and resources into creating [best in class open source packages](https://github.com/erlandmuchasaj?tab=repositories).

If you found this package helpful you can show support by clicking on the following button below and donating some amount to help me work on these projects frequently.

[ ![buy me a coffee](https://camo.githubusercontent.com/58c5ff7fa04b3393e6eb6103b591ef6dceee6e1c64dc924ba2713a86b51d8cb7/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f67756964656c696e65732f646f776e6c6f61642d6173736574732d322e737667)](https://www.buymeacoffee.com/erland)Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please see [SECURITY](SECURITY.md) for details.

Credits
-------

[](#credits)

- [Erland Muchasaj](https://github.com/erlandmuchasaj)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance88

Actively maintained with recent releases

Popularity45

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.8% 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 ~56 days

Total

19

Last Release

56d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d7469281a88a626e0fa6ba92fad648de2d1151e931b0ef844446539aa73660a?d=identicon)[erlandmuchasaj](/maintainers/erlandmuchasaj)

---

Top Contributors

[![erlandmuchasaj](https://avatars.githubusercontent.com/u/6152399?v=4)](https://github.com/erlandmuchasaj "erlandmuchasaj (31 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![Ajility97](https://avatars.githubusercontent.com/u/68575573?v=4)](https://github.com/Ajility97 "Ajility97 (1 commits)")[![harryqt](https://avatars.githubusercontent.com/u/18257605?v=4)](https://github.com/harryqt "harryqt (1 commits)")[![Pr3d4dor](https://avatars.githubusercontent.com/u/13210429?v=4)](https://github.com/Pr3d4dor "Pr3d4dor (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

responselaravelpackagelibrarycmsgzipoptimizeemcms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/erlandmuchasaj-laravel-gzip/health.svg)

```
[![Health](https://phpackages.com/badges/erlandmuchasaj-laravel-gzip/health.svg)](https://phpackages.com/packages/erlandmuchasaj-laravel-gzip)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M131](/packages/laravel-pulse)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)

PHPackages © 2026

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