Headers don’t get set in Laravel 5.6
I’m using Laravel 5.6.
I’m trying to cache my css/js files. The way I’m doing it is using a middleware.
public function handle($request, Closure $next, $guard = null)
{
$request->header('Cache-Control', 'max-age=86400, public');
$request->header('X-www-test-header', 'test-value');
return $next($request);
}
And wrapping basically every route in this middleware. This seems like a really bad idea from where I’m standing but to be perfectly honest I can’t find another way to do it(any suggestions are welcome). But that’s not the problem.
The problem is that my headers don’t make thru.
I’ve also tried setting the headers via .htaccess
<IfModule mod_headers.c>
<filesmatch ".(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
<filesmatch ".(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
<filesmatch ".(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
<FilesMatch ".(js|css)$">
ExpiresActive On
ExpiresDefault "access plus 1 weeks"
</FilesMatch>
That doesn’t work either.
I’m honestly not sure what the problem is. Either laravel is somehow rewriting all the headers or apache or something.
Literally any pointing in the right direction is appreciated.
from Laravel Questions and Answers https://laravelquestions.com/php/headers-dont-get-set-in-laravel-5-6/
via Lzo Media
No comments:
Post a Comment