如何为我的网站中的index.html页面配置最佳缓存策略?
我有一个带有 index.html 主页的网站,该主页会不时更新。我们有时会为客户添加优惠、特殊消息等,这些信息必须在第二天对每个人都可见。
如果 index.html 被浏览器缓存,许多用户将不会注意到任何内容发生了变化,除非他们显式刷新页面内容...
这是确保 100% 访问者拥有最新内容的最佳方法index.html 页面,而不影响缓存性能?
I have a web site with an index.html homepage that is updated from time to time. We sometimes add offers for our clients, special messages and so on, which have to be visible by next day for everyone.
If index.html is cached by browsers, many users will not notice that anything has changed, unless they explicitly refresh the contents of the page...
Which is the best way to be sure that 100% visitors have an up-to-date index.html page, without compromising cache performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最好的答案是跳过每次更新 index.html 并使用服务器端编程语言,例如 PHP。然后,您可以将页面的标头设置为不缓存,还可以设置可用于更改内容的管理页面。或者您可以使用 AJAX 使用带有 JavaScript 的浏览器端脚本。然后页面就可以在下次加载站点之前进行更新。
My best answer would be to skip out on updating the index.html each time and go with a server-side programming language, like PHP. You can then set the headers for the page to not cache, and you can also set up an admin page that you can use to change the content. Or you could go with a browser-side script with JavaScript using AJAX. Then the page has an ability to update before the next loading of the site.