当页面管理员通过Web表单和数据库表更改几个属性时,我有一个覆盖CSS文件的网页。 我的问题是,浏览器有时会缓存旧文件并忽略新版本。 有人建议我应该使用文件版本控制方案,它基本上会改变文件的名称,这样我就不必担心浏览器缓存旧版本。 除了版本控制方案之外,还有其他解决此问题的方法吗?
I have a web page that over_writes a CSS file when the page admin changes a few attributes through a web form and a database table. My problem is that the browser sometimes caches the old file and ignores the new version. It has been suggested to me that I should use a file versioning scheme that would basically change the name of the file so that I would never have to worry about the browser caching the old version. Is there any other way around this problem besides the versioning scheme?
最满意答案
将HTML文件包含在HTML标头中时,可以简单地向查询字符串添加一个参数:
<link rel="stylesheet" href="style.css?v=2">在你的情况下,你可以每次页面管理改变一些东西时,以编程的方式增加这个数字(假设你已经设置了$cssVersion ):
<link rel="stylesheet" href="style.css?v=<?php echo $cssVersion; ?>">您必须将$cssVersion存储在数据库列或文件中。
When including your CSS file in the HTML header, you could simply add a parameter to the query string:
<link rel="stylesheet" href="style.css?v=2">In your case, you could increment this number programmatically every time the page admin changes something (assuming you have set $cssVersion somewhere):
<link rel="stylesheet" href="style.css?v=<?php echo $cssVersion; ?>">You would have to store $cssVersion in a database column or in a file.
更多推荐
发布评论