简体   繁体   English

是否不添加缓存meta + php标头会导致css / js也不缓存?

[英]Will adding no cache meta + php headers cause css/js not to cache too?

Had a problem with the dynamic site (100% ajax) not updating when it goes to different pages. 动态网站(100%Ajax)转到不同页面时出现问题,无法更新。 I just want to cache the html pages. 我只想缓存html页面。 The css and js is unchanging, I WANT that to cache you know? CSS和JS不变,我想缓存您知道吗?

I added the following php 我添加了以下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');

and the following html 和以下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" />

will it disrupt the css/js or JUST make the html have to reload. 它会打乱CSS / JS还是让HTML必须重新加载。

"I just want to cache the html pages" in your question is a bit confusing. 您的问题中的“我只想缓存html页面”有点令人困惑。 From what I gather your problem is that the browser caches the content but you want to DISABLE the caching. 据我所知,您的问题是浏览器缓存内容,但您要禁用缓存。 :) :)

Anyways: 无论如何:

Whatever you add in your PHP output only affects your PHP output. 无论您在PHP输出中添加什么内容,都只会影响PHP输出。 If you produce HTML in your PHP scripts, then only the HTML produced by PHP is affected, nothing else. 如果在PHP脚本中生成HTML,则仅影响PHP生成的HTML,而没有其他影响。

Bonus answer: 奖励答案:

Should you wish to change the caching policies for .js and .css files, then you need to manhandle Apache's httpd.conf or .htaccess (assuming Apache is your HTTP server) 如果您希望更改.js和.css文件的缓存策略,则需要处理Apache的httpd.conf或.htaccess(假设Apache是​​您的HTTP服务器)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM