让浏览器缓存我的动态PHP样式表 [英] Let browsers cache my dynamic PHP stylesheet

查看:165
本文介绍了让浏览器缓存我的动态PHP样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PHP文件(styles.php)创建一个样式表,使得样式表变成动态的,取决于谁要求是用户。为每个用户样式表是恒定的,因此应当对他的客户端浏览器缓存。

I want to create a stylesheet in a PHP file (styles.php), such that the stylesheet becomes dynamic, depending on the user who requests is. For each individual user the stylesheet is constant, and should therefore be cached on his client browser.

我已阅读,您可以通过为Content-Type和Cache-Control和设置等头实现这一点,但我不能得到这个工作。显然有更多的它,也许它甚至是不可能的。浏览器不似乎总是听缓存头。

I have read that you can achieve this by setting headers for content-type and cache-control and such, but I can't get this to work. Apparently there's more to it, and maybe it is not even possible. Browsers don't always seem to listen to caching headers.

有谁知道需要什么来让PHP文件浏览器缓存?

Does anyone know what is required to let a PHP file be cached in the browser?

我不想把所有的动态CSS在HTML样式块,我不想改变我的Apache配置这一点。如果是真正不可能的我想要什么,我也想知道。谢谢!

I don't want to put all the dynamic CSS in a style-block in the HTML, and I don't want to change my Apache configuration for this. If it's truly not possible what I want, I also would like to know. Thanks!

推荐答案

这些标题应该很好地工作:

These headers should work fine:

$expires = 60*60*24; // how long to cache in secs..
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header('Content-type: text/css');

这篇关于让浏览器缓存我的动态PHP样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆