Ad
Laravel 5 How To Set Cache-Control HTTP Header Globally?
My Laravel application is returning Cache-Control: no-cache, private
HTTP header by default for each site. How can I change this behaviour?
P.S.: It is not a PHP.ini problem, because changing session.cache_limiter
to empty/public does not change anything.
Ad
Answer
Laravel 5.5 <
You can have a global middleware for that. something like:
<?php
namespace App\Http\Middleware;
use Closure;
class CacheControl
{
public function handle($request, Closure $next)
{
$response = $next($request);
$response->header('Cache-Control', 'no-cache, must-revalidate');
// Or whatever you want it to be:
// $response->header('Cache-Control', 'max-age=100');
return $response;
}
}
then just register this as a global middleware in the Kernel file:
protected $middleware = [
....
\App\Http\Middleware\CacheControl::class
];
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad