【问题标题】:Is there nowadays a crossbrowser and standard compliant way to prevent caching when using an XMLHttpRequest?现在有没有一种跨浏览器和标准兼容的方法来防止在使用 XMLHttpRequest 时进行缓存?
【发布时间】:2016-03-14 03:39:49
【问题描述】:

现在有没有一种跨浏览器和符合标准的方法来防止在使用 XMLHttpRequest 时进行缓存?

到目前为止,甚至 MDN 都提出了一种解决方法。 (MDN XMLHttpRequest#Bypassing_the_cache)

(如Add a random query string to the URL you are sending.

编辑:问题是关于告诉浏览器不要使用它的客户端缓存,独立于服务器作为标志或字段发送的内容。

【问题讨论】:

  • 正确的方法是让服务器告诉不要缓存任何东西。在这种情况下,如果浏览器按照他们说的做,就不需要变通方法。
  • 缓存控制实际上是服务器的责任,因为它应该知道它所服务的资源的性质。
  • 不,没有这种方法。

标签: javascript cross-browser xmlhttprequest standards cache-control


【解决方案1】:

您可以使用Cache-Control 标头控制缓存数据的方式

类似这样的东西 - cache-control: private, max-age=0, no-cache

在此处阅读更多信息 - http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/ https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en

【讨论】:

  • 这是一个服务器端解决方案,但 OP 已将问题修改为只需要客户端解决方案。
猜你喜欢
  • 1970-01-01
  • 2011-03-10
  • 1970-01-01
  • 2010-09-19
  • 2013-02-17
  • 1970-01-01
  • 2015-08-26
  • 1970-01-01
  • 2011-04-28
相关资源
最近更新 更多