文件版本控制可以消除浏览器缓存问题(File versioning to eliminate browser caching problems)

编程入门 行业动态 更新时间:2024-10-05 03:29:07
文件版本控制可以消除浏览器缓存问题(File versioning to eliminate browser caching problems)

当页面管理员通过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.

更多推荐

本文发布于:2023-07-09 10:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085607.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   浏览器   版本   文件   File

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!