使用PHP动态禁用Javascript / CSS的缓存?
I've coded an option called 'devmode' in my web app, which basically means 'no caching'. The app normally outputs an automatically minified (and aggregated) version of the Javascript and CSS, but the devmode option overrides this.
However, we still have the browser cache. So, without further ado, how can I disable caching of ALL components on a page if a certain PHP boolean is true?
Cheers
Edit: might interest you to know that I'm running Apache, and one idea I had was to force .js and .css to be parsed as PHP (which is straightforward), and somehow 'inject' a little piece of PHP code at the start of each.
我在我的网络应用程序中编写了一个名为“devmode”的选项,这基本上意味着“没有缓存”。 该应用程序通常会输出Javascript和CSS的自动缩小(和聚合)版本,但devmode选项会覆盖此。 p>
但是,我们仍然拥有浏览器缓存。 那么,如果某个PHP布尔值为真,我怎么能禁用页面上所有组件的缓存? p>
干杯 p>
编辑: 你可能会感兴趣我知道我正在运行Apache,我有一个想法就是强制.js和.css被解析为PHP(这很简单),并且在某种程度上“注入”了一小段PHP代码 每个。 p> div>
A "quick and dirty" approach for debugging/developing, you could call all components in your HTML with a random (or time-based) query-string. For instance:
<img src="logo.png?uniqecall=20111026035500" />
, which would look like this in your PHP code:
print '<img src="logo.png?uniqecall=' . date("YmdHis") . '" />';
etc...
.htaccess
RewriteRule ^no-cache/(.*?)$ no-cache.php?file=$1 [QSA,L]
no-cache.php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
readfile('static/'.$_GET['file']);
Assuming you won't hack yourself :)