Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Etag Middleware

Laravel Etag Middleware Laravel Package

matthewbdaly/laravel-etag-middleware

Laravel middleware that automatically adds ETag headers to responses, enabling conditional GET requests and 304 Not Modified replies so clients can cache efficiently and save bandwidth. Simple to register and configure per route.

View on GitHub
Deep Wiki
Context7

A Laravel middleware for adding ETags to HTTP requests to improve response times

Frequently asked questions about Laravel Etag Middleware
How do I install matthewbdaly/laravel-etag-middleware?
Install it with Composer using composer require matthewbdaly/laravel-etag-middleware. Then register the middleware class in app/Http/Kernel.php, either globally or on a route group such as api. Because the last release targets Laravel 5–7 era constraints, confirm Composer resolves it for your Laravel version before relying on it.
Does laravel-etag-middleware support Laravel 10, 11, or 12?
It likely will not resolve out of the box because the last release was September 2020 and targets Laravel 5–7 era constraints. You can widen the Composer constraints, fork the package, or vendor the middleware class into app/Http/Middleware. The MIT license makes vendoring trivial and legally clean, which is often the lower-risk path.
How does the Laravel ETag middleware work?
The middleware hashes the outgoing response body into an ETag header. On later requests it compares the request's If-None-Match value and returns a 304 Not Modified response when it matches. The application still renders the full response to compute the hash, so the gain is bandwidth and client-perceived latency rather than application CPU.
Should I register the ETag middleware globally or only on specific routes?
Prefer explicit route scoping to genuinely cacheable, idempotent GET endpoints. Global registration risks incorrect 304 responses on authenticated, personalized, streaming, download, or already-ETagged responses. Pair route scoping with a configuration flag such as ETAG_ENABLED so rollout and rollback are configuration changes rather than deploys.
Does adding ETags with this middleware improve Laravel application performance?
It improves bandwidth usage and client-perceived latency by letting repeat clients skip the response payload. It does not reduce server-side rendering CPU because Laravel still builds the full response before the middleware hashes it. If a CDN or reverse proxy already issues ETags, the marginal benefit drops sharply and double-hashing is wasted work.
Why am I getting stale content or incorrect 304 responses with ETag middleware?
ETags must be deterministic per representation, so non-deterministic bodies such as CSRF tokens, timestamps, debug output, or per-user personalization can produce incorrect 304s. Shared caches can also collide without a correct Vary header on personalized responses. Exclude personalized routes and verify that any CDN or proxy ETag behavior does not conflict with the middleware.
How should I handle streamed, file download, or SSE responses with this ETag middleware?
The middleware does not reason about streamed responses, BinaryFileResponse downloads, SSE, or responses that already set their own ETag. These are edge cases that should be excluded from the middleware's route scope. Hashing streamed bodies is especially problematic, so keep the middleware away from those endpoints.
Do I need this package if Laravel and Symfony already support ETags?
Laravel responses extend Symfony's Response, which already exposes setEtag() and isNotModified(). The functional delta of this package is small, and an in-house middleware wrapping those methods can be roughly 40–60 lines. Use the package as a timeboxed accelerator only if Composer resolves it and it passes your correctness checks.
Is matthewbdaly/laravel-etag-middleware maintained?
It has 64 stars, a single maintainer, and no release in roughly five years. Treat it as unmaintained code you are adopting rather than a supported dependency. The MIT license allows vendoring or forking, but do not position it as a platform dependency; it is a tactical optimization with an exit ramp.
How should I test Laravel ETag middleware before production?
Use curl -I against a known route to confirm the ETag header is present, then send If-None-Match to verify a bodyless 304 response. Test repeat requests, authenticated or personalized endpoints, streaming and download routes, and any CDN or proxy behavior. Ship behind an ETAG_ENABLED flag with explicit route scoping, and confirm clients actually send If-None-Match and handle 304 responses correctly.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels