如何确保网站访问者看到重新设计的页面而不是旧的缓存页面和图形?
我最近重新设计了我的网站,新的 CSS、新的按钮图形等。当现有用户返回我的网站时,我想确保他们获得新的页面和样式表,并且浏览器不会尝试加载旧的样式表等
。标题看起来像这样 -
我有一个公共页面的头文件 -
<meta http-equiv="expires" content="Tue, 16 Feb 2019 09:00:00 GMT">
<meta http-equiv="cache-control" content="max-age=315360000">
以及网站内页面的头文件(用户登录后)
<meta http-equiv="expires" content="Mon, 04 Dec 1999 21:29:02 GMT">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
我认为网站内的页面可能会新鲜提供因为缓存控制指定没有缓存等等。但是我的公共页面访问者仍然会看到缓存版本吗?我是否也应该将相同的缓存控制标记添加到公共页面的头文件中?
我做的另一件事是向新的 css 文件添加一个查询字符串以强制新的加载 -
例如 -
<link rel="stylesheet" href="css/styles.css?new" type="text/css" >
还有其他好的建议/最佳实践吗?
谢谢!
Ive recently redesigned my website, new CSS, new graphics for buttons etc. When existing users return to my site I want to make sure they get served the new pages and style sheets and the browsers dont try to load the old stylesheets etc.
Previously my headers looked like this -
I have a header file for the public pages -
<meta http-equiv="expires" content="Tue, 16 Feb 2019 09:00:00 GMT">
<meta http-equiv="cache-control" content="max-age=315360000">
And a header file for the pages inside the site (after a user has logged on)
<meta http-equiv="expires" content="Mon, 04 Dec 1999 21:29:02 GMT">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
I'm thinking that its likely that the pages inside the site will be served fresh as the cache control has specified no cache etc. But will my visitors to the public pages still see cached versions? Should I add teh same cache-control tags to the header file for the public pages too?
One other thing i did was to add a query string to the new css file to force a new load -
eg -
<link rel="stylesheet" href="css/styles.css?new" type="text/css" >
Any other good advice / best practices for this?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
2019 年到期是一个相当大的承诺。你是说他们不需要检查未来 8 年的更新。
所以,是的,您至少应该从公共页面中删除这些标头,如果您想 100% 确定,则添加其他标头。如果您将它们排除在外,浏览器将根据上次修改的 http 标头来猜测它们可以使用缓存版本多长时间。
但是,您应该仅使用第 1 行和第 4 行。Pragma 不执行任何操作(仅使用客户端到服务器,而不使用服务器到客户端)。 Double expires 没有任何用处,-1 是无效值。
Expires 2019 is quite a commitment. You are saying they need not check for updates for the next 8 years.
So yes, you should at least remove those headers from the public pages, and add the other headers if you want to be 100% sure. If you leave them out browsers will guess how long they can use the cached version based mostly on the last-modified http-header.
You should however only use line 1 and 4. Pragma doesn't do anything (only use client-to-server not server-to-client). Double expires doesn't have any use and -1 is an invalid value.