Download the PHP package open-southeners/laravel-vapor-response-compression without Composer
On this page you can find all versions of the php package open-southeners/laravel-vapor-response-compression. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download open-southeners/laravel-vapor-response-compression
More information about open-southeners/laravel-vapor-response-compression
Files in open-southeners/laravel-vapor-response-compression
Package laravel-vapor-response-compression
Short Description Add server-side response compression with a range of different algorithms (Gzip, brotli, deflate...)
License MIT
Informations about the package laravel-vapor-response-compression
Laravel Response Compression
Add server-side response compression with a range of different algorithms (Gzip, brotli, deflate...)
Why use this package?
The reason why is because AWS hard limit its API Gateway service to 10MB (at the date of writing this), and by hard we mean that there's no way you can increase this limitation.
Note: Thought CloudFlare is a good solution for the end user, it doesn't solve this issue as CloudFlare does this between the server and the client, so the response already passed through AWS (API Gateway).
Read more here: https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#http-api-quotas
Or on our blog article: https://opensoutheners.com/how-to-prevent-large-responses-to-trigger-502-errors
Getting started
Then publish the configuration file defaults into your application's config folder:
Then add the following to you app/Http/Kernel.php
as a global middleware:
Note: Remember this is different in older versions of Laravel, Laravel 9 should look like the following.
Configuration
If you already have this config/response-compression.php
file, you can skip this step, otherwise please use the following artisan command first:
Note: As for smaller responses this threshold will prevent to compress the response if it doesn't reach an specific number of bytes. We encourage you to configure this and not leave it as ±0 bytes otherwise response will be always compressed.
This configuration is defaulted to 10000 bytes, you may customise this as your application demands.
Setting up Brotli extension in Vapor
First of all, this will require you to use Docker containers on your Vapor environments if you're not familiar with them, you can still use this extension as it uses the first client requested algorithm available at server side.
👉 Read more about using containers in Vapor here
Anyway, in case you want to proceed, add this to your environment Dockerfile(s), please use comments as references only:
And ensure your project depends on vdechenaux/brotli.
Alternative Brotli setup
Another alternative is to use: https://github.com/kjdev/php-ext-brotli
TODO: Setup instructions for Vapor/Dockerfile
Credits
- To @jryd_13 for writing the article that [gave me this idea]()
All versions of laravel-vapor-response-compression with dependencies
ext-zlib Version ^7.2 || ^8.0