Category: Laravel

I was answering some Laravel questions on StackOverflow this week when I stumbled on a question asking how to enable GZIP compression on responses when using Laravel Vapor. We host a number of applications on Laravel Vapor and this was something we'd solved, but a cursory search of Google didn't return anything that explained how to do this (at least at the time this was written).

Assuming we want to encode the response and are able to, we set the content of the response to be the compressed version.

Like any middleware, you can choose to apply this at a per route level, add it to a particular group of middleware, or add it as global middleware. In our apps, we've added it as global middleware and then we just ask for a GZIP'd response when we need to do so.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners