我怎样才能保证一个Ajax响应将被缓存?将被、缓存、Ajax

2023-09-10 18:02:33 作者:难熬

我想打一个Ajax调用,但我想,以确保它会被缓存。 我使用jQuery的。

I want to make an ajax call, but I want to make sure it will be cached. I am using jquery.

有没有一种方法,以确保请求保留在缓存中最流行的浏览器?

Is there a way to make sure the request stays in the cache for most popular browsers?

推荐答案

使用jQuery,你可能会想明确地添加了If-Modified-由于与标头中的 ifModified 选项​​,该选项默认为false:

With jQuery, you will probably want to explicitly add the If-Modified-Since header with the ifModified option, which is false by default:

$.ajax({
     ...
     ifModified: true,
     ...
});

还有一个缓存选项,你会需要强制如此,如果你的数据类型为 JSONP 剧本。这是真的,默认情况下,其他的数据类型。

There's also a cache option that you'll need to force true if your dataType is jsonp or script. It's true by default for other dataTypes.

请参见 jQuery.ajax()文档对这些选项的说明。

See the jQuery.ajax() docs for a description of these options.

 
精彩推荐
图片推荐