本文介紹了Laravel 5 如何全局設置 Cache-Control HTTP 標頭?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我的 Laravel 應用程序默認為每個站點返回 Cache-Control: no-cache, private
HTTP 標頭.我該如何改變這種行為?
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.:這不是 PHP.ini 的問題,因為將 session.cache_limiter
更改為 empty/public 不會改變任何東西.
P.S.: It is not a PHP.ini problem, because changing session.cache_limiter
to empty/public does not change anything.
推薦答案
Laravel 5.5 <
您可以為此擁有一個全局中間件.類似:
Laravel 5.5 <
You can have a global middleware for that. something like:
<?php
namespace AppHttpMiddleware;
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 = [
....
AppHttpMiddlewareCacheControl::class
];
這篇關于Laravel 5 如何全局設置 Cache-Control HTTP 標頭?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!