我怎样才能保证一个Ajax响应将被缓存? [英] How can I guarantee that an ajax response will be cached?

查看:86
本文介绍了我怎样才能保证一个Ajax响应将被缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个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.

这篇关于我怎样才能保证一个Ajax响应将被缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆