30 lines
829 B
PHP
30 lines
829 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DisableAssetCacheInDebug
|
|
{
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
$response = $next($request);
|
|
|
|
if (config('app.debug')) {
|
|
$contentType = $response->headers->get('Content-Type', '');
|
|
$isBinaryFile = str_starts_with($contentType, 'image/')
|
|
|| str_starts_with($contentType, 'video/')
|
|
|| str_starts_with($contentType, 'audio/')
|
|
|| str_starts_with($contentType, 'application/pdf');
|
|
|
|
if (!$isBinaryFile) {
|
|
$response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate');
|
|
$response->headers->set('Expires', '0');
|
|
}
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|