adsazad/symfony-etagging
Symfony bundle that adds easy ETag support to any Response. Inject EtaggingInterface and wrap rendered responses with etagResponse() to enable caching/conditional requests. Supports custom headers plus configurable max-age and shared max-age.
Cache-Control, Expires), which aligns well with modern web performance best practices (e.g., RFC 7232). It is particularly useful for static or semi-static content (e.g., blogs, marketing pages, or API responses with infrequent updates).EtaggingInterface could be adapted into a Laravel middleware or service provider, but this requires custom glue code.Response object directly. In Laravel, responses are typically handled via Illuminate\Http\Response or Illuminate\Contracts\Http\Kernel::handle().addCustom() and setMaxAge() methods are straightforward but require manual invocation in each relevant endpoint.| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| Laravel-Symfony Gap | Package assumes Symfony’s DI and event system; Laravel uses a different paradigm. | Abstract into a Laravel service or middleware with adapter layer. |
| Caching Invalidation | Shared Max-Age may cause stale content if not managed (e.g., user-specific data). |
Use Vary: User-Agent or private caching where applicable. |
| Performance Overhead | ETag generation adds minor CPU overhead; may not justify benefits for highly dynamic apps. | Benchmark with real traffic before widespread adoption. |
| API Compatibility | ETags are less common in APIs (prefer Last-Modified or ETag headers manually). |
Restrict usage to HTML responses or document API limitations. |
| License Compliance | MIT license is permissive, but custom integration may require internal review. | Ensure no conflicts with existing Laravel licensing (e.g., proprietary extensions). |
etagResponse() calls in controllers lead to maintenance overhead?Cache::tags(), response()->header()) instead?Cache-Control) can be replicated in Laravel via:
EtagMiddleware).Response class to support etag().Symfony HttpFoundation (which underpins Laravel’s Response) to minimize friction.etagResponse() for a subset of routes./about, /blog/*).304 Not Modified responses work.etagResponse() calls with middleware or response filters.addCustom()) via middleware.Max-Age in a central location (e.g., config/caching.php)./dashboard, API endpoints).Cache-Control rules).Max-Age.| Component | Compatibility Notes |
|---|---|
| Laravel 10+ | High (uses Symfony HttpFoundation v6+). |
| Laravel 8/9 | Medium (may require minor adapter layer for DI). |
| API Responses | Low (ETags are less common; prefer Last-Modified or manual ETag headers). |
| SPAs/JS Frameworks | High (works for static HTML served via Laravel). |
| Headless CMS | High (if content is static or versioned). |
| Real-Time Features | Low (e.g., WebSockets, Server-Sent Events). |
?id=USER_ID or Accept: application/json.304 responses.Max-Age based on traffic patterns.200 OK responses for unchanged content.Cache-Control headers (e.g., from CDN).Cache::tags('public')) to manage invalidation.304 vs. 200 responses requires HTTP header inspection.Max-Age is too long.Response events.ETag and Cache-Control headers.Cache::forget() + etagResponse bypass).Vary header usage).How can I help you explore Laravel packages today?