gpt4 book ai didi

http - 浏览器中的缓存是自动的吗?

转载 作者:可可西里 更新时间:2023-11-01 15:07:35 26 4
gpt4 key购买 nike

我有一个向 REST API 发送请求的 JavaScript 应用程序,来自服务器的响应具有缓存 header (如 ETag、缓存控制、过期)。浏览器中的响应缓存是自动的,还是应用必须实现某种机制来保存数据?

最佳答案

AJAX 请求与普通请求没有什么不同 - 它是 GET/POST/HEAD/浏览器发送的任何请求,并且是这样处理的。这是确认here :

The HTTP and Cache sub-systems of modern browsers are at a much lower level than Ajax’s XMLHttpRequest object. At this level, the browser doesn’t know or care about Ajax requests. It simply obeys the normal HTTP caching rules based on the response headers returned from the server.

根据 the jQuery documentation , 缓存也可以至少以一种通常的方式失效(附加查询字符串):

cache (default: true, false for dataType 'script' and 'jsonp')

Type: Boolean

If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.

简而言之,给定相同的 header ,AJAX 响应的缓存方式与其他请求相同。

关于http - 浏览器中的缓存是自动的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30824092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com