0

动态站点(100% ajax)在转到不同页面时没有更新。我只想缓存html页面。css 和 js 是不变的,我想缓存你知道吗?

我添加了以下php

Response::header('Cache-Control', 'no-store, private, no-cache, must-revalidate'); // HTTP/1.1
Response::header('Cache-Control', 'pre-check=0, post-check=0, max-age=0, max-stale = 0', false); // HTTP/1.1
Response::header('Pragma', ' public');
Response::header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');                  // Date in the past  
Response::header('Expires', '0', false); 
Response::header('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
Response::header('Pragma', 'no-cache');

和以下html

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

它会破坏 css/js 还是只是让 html 必须重新加载。

4

1 回答 1

1

您的问题中的“我只想缓存 html 页面”有点令人困惑。从我收集到的问题来看,浏览器缓存了内容,但您想禁用缓存。:)

无论如何:

无论您在 PHP 输出中添加什么,都只会影响您的 PHP 输出。如果您在 PHP 脚本中生成 HTML,那么只有 PHP 生成的 HTML 会受到影响,没有其他影响。

奖励答案:

如果您希望更改 .js 和 .css 文件的缓存策略,那么您需要处理 Apache 的 httpd.conf 或 .htaccess(假设 Apache 是您的 HTTP 服务器)

于 2013-09-28T08:46:50.007 回答