gpt4 book ai didi

javascript - 不添加缓存 meta + php header 会导致 css/js 也不会缓存吗?

转载 作者:太空宇宙 更新时间:2023-11-04 14:32:11 26 4
gpt4 key购买 nike

动态站点(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 必须重新加载。

最佳答案

您问题中的“我只想缓存 html 页面”有点令人困惑。据我了解,您的问题是浏览器缓存了内容,但您想禁用缓存。 :)

无论如何:

无论您在 PHP 输出中添加什么,只会影响您的 PHP 输出。如果您在 PHP 脚本中生成 HTML,则只有 PHP 生成的 HTML 会受到影响,而不会受到影响。

奖励答案:

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

关于javascript - 不添加缓存 meta + php header 会导致 css/js 也不会缓存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19065067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com