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.2.6(2mo ago)40129.3k—1.8%8[1 PRs](https://github.com/erlandmuchasaj/laravel-gzip/pulls)2MITPHPPHP ^8.0

Since Jul 26Pushed 2mo 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 1mo ago

READMEChangelogDependencies (18)Versions (20)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

55

—

FairBetter than 98% of packages

Maintenance84

Actively maintained with recent releases

Popularity45

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.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 ~55 days

Total

18

Last Release

81d 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 (28 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)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (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

[yajra/laravel-datatables-oracle

jQuery DataTables API for Laravel

4.9k33.8M339](/packages/yajra-laravel-datatables-oracle)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[erlandmuchasaj/laravel-file-uploader

A simple package to help you easily upload files to your laravel project.

128.7k](/packages/erlandmuchasaj-laravel-file-uploader)

PHPackages © 2026

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