在Javascript中你如何检查,如果用户有一个文件的缓存版本? [英] In Javascript how do you check if the User has a Cached version of a file?

查看:126
本文介绍了在Javascript中你如何检查,如果用户有一个文件的缓存版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/12830425/how-to-detect-when-xhr-returns-a-cached-resource\">How当XHR返回一个缓存的资源来检测?

我建的,只有当它尚未使用与jQuery加载这个页面上加载JavaScript文件自动加载器:

I built an auto loader that only loads a javascript file if it has not already been loaded on this page using jquery with:

$.getScript();

我首先检查是否存在的功能,如果他们不让我加载它们。然而,这是无法解释的浏览器缓存,我希望我也许能弄清楚如何。

I first check if the functions exist and if they do not I load them. However, this is unable to account for the browsers cache, I was hoping I might be able to figure out how.

有一件事我想补充它是看用户是否已经保存在他们的浏览器缓存中的文件。是否有可能以检查是否从您的​​服务器的文件已经被缓存在用户的浏览器,这样我就可以跳过使得调用服务器呢?

One thing I would like to add to it is to see if the user already has the file saved in their browsers cache. Is it possible to check if a file from your server has already been cached on the users browser, so that I can skip making the call to the server at all?

推荐答案

缓存透明地工作。如果请求的文件,并在该文件中的用户的缓存中存在,则该高速缓存文件将被使用,不会有对服务器的附加请求。浏览器采用的是照顾,所以你不必担心它对于您所描述的情况。

The cache works transparently. If you request a file and the file exists in the user's cache, then the cached file will be used and there will not be an additional request to the server. The browser takes care of that, so you don't have to worry about it for the case that you're describing.

.getScript 默认禁用此使用时间戳的查询参数,所以你只需要禁用缓存旁路其中 getScript加入用途:

.getScript by default disables this using timestamped query arguments, so you simply need to disable the cache bypass which getScript uses:

$.ajaxSetup({
  cache: true
});

这篇关于在Javascript中你如何检查,如果用户有一个文件的缓存版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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