如何确保浏览器缓存

问题描述 投票:0回答:1

我的 htaccess 文件中有这个:

<IfModule mod_expires.c>
<FilesMatch "\.(gif|png|jpg|jpeg|svg|webp|css|swf|ico|eot|woff|js)$">
  ExpiresActive On
  ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>

Header set Cache-Control "max-age=31536000, public"

我的 php 文件中有这个:

if(session_id()=='') session_start();
session_write_close();
header('Cache-Control:max-age=2592000'); 

然而,当我在cache-checker.com上测试页面时,我得到了这样的响应:

Server: Apache
X-Powered-By: PHP/7.4.33
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-Frame-Options: DENY
Set-Cookie: PHPSESSID=5f662c687f5b5e3459a01c0a896ec11f; path=/
Referrer-Policy: strict-origin-when-cross-origin
Upgrade: h2
Connection: keep-alive
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=631138519; includeSubDomains
X-XSS-Protection: 1; mode=block
Content-Type: text/html; charset=utf-8

我正在尝试启用浏览器缓存。

如有任何帮助,我们将不胜感激。

php .htaccess caching cache-control
1个回答
0
投票

经过大量额外搜索后,我找到了解决方案。

添加行:

session_cache_limiter('public');

之前:

session_start();
© www.soinside.com 2019 - 2024. All rights reserved.