vinkius-labs/laravel-page-speed
Optimize Laravel HTML and API responses with a configurable middleware pipeline: minify HTML/JSON/XML, add cache headers, ETags, compression and more. Works across Laravel 10–13 with any cache store (Redis, Memcached, file, etc.) for faster, leaner responses.
X-Response-Time, X-Cache-Status) for integration with APM tools (Datadog, New Relic), which is critical for performance monitoring in production.web/api groups in Kernel.php or bootstrap/app.php).config/laravel-page-speed.php) allows fine-grained tuning (e.g., enabling/disabling specific optimizations, cache drivers, compression thresholds).InlineCss or CollapseWhitespace may break dynamic frameworks (Livewire, Alpine.js, Vue, Angular) if not configured carefully.wire:, x-data, ng-class attributes) and debug modes to skip problematic routes.API_CACHE_TTL=300) could invalidate stale data if not aligned with business logic.POST requests bypass cache).InlineCss/CollapseWhitespace middleware are excluded or configured for these routes.API_CACHE_TTL be shorter for dynamic data (e.g., 60s) vs. static data (e.g., 300s)?X-Response-Time) already ingested by APM tools? If not, plan for Datadog/New Relic integration.DeferJavascript first) or rolled out all-at-once?strtr for performance).ApiResponseCache, ApiResponseCompression, and ApiSecurityHeaders.InlineCss, DeferJavascript, and CollapseWhitespace only on non-framework routes.ApiResponseCache should run before ApiETag).Debugbar, Telescope, or Horizon.Cache-Control headers unless explicitly overridden.| Step | Action | Dependencies | Validation |
|---|---|---|---|
| 1 | Install package | Composer, PHP 8.2+ | composer require vinkius-labs/laravel-page-speed |
| 2 | Publish config | vendor:publish |
php artisan vendor:publish --provider="VinkiusLabs\LaravelPageSpeed\ServiceProvider" |
| 3 | Configure .env |
Cache driver, TTL | Set LARAVEL_PAGE_SPEED_ENABLE=true, API_CACHE_DRIVER=redis |
| 4 | Add API middleware | Kernel.php/bootstrap/app.php |
Append to api group |
| 5 | Add web middleware | Kernel.php/bootstrap/app.php |
Append to web group (test non-framework routes first) |
| 6 | Test in staging | Load testing, Lighthouse | Validate payload size, latency, and cache hits |
| 7 | Monitor production | APM, logs | Watch X-Cache-Status, X-Response-Time headers |
LARAVEL_PAGE_SPEED_ENABLE may not reflect if stale static caches exist (e.g., in persistent environments like Laravel Octane).php artisan cache:clear) or use dynamic configuration reloads.php artisan cache:forget) may not trigger dynamic tag invalidation.Cache::tags()->flush() for tagged routes or event-based invalidation (e.g., Model::saved()).X-Cache-Status and X-Circuit-Breaker-State to diagnose issues.LARAVEL_PAGE_SPEED_DEBUG=true for verbose output.InlineCss (check for malformed HTML).API_CACHE_TTL is too short; monitor `X-CacheHow can I help you explore Laravel packages today?