根据 jQuery 文档 (https://api.jquery.com/jquery.getscript/) 使用更灵活的 $.ajax()
方法,但它不适用于此处描述的我 (jQuery cannot load plugin file using ajax before calling the plugin function, thus, gives kind of weird result)
By default,
$.getScript()
sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using$.ajaxSetup()
:
$.ajaxSetup({
cache: true
});
但我需要缓存一些内容,而不是全部。
Alternatively, you could define a new method that uses the more flexible
$.ajax()
method.
它对我不起作用,因为它不能保证按顺序加载文件。
现在这种情况的最佳解决方案是什么?
最佳答案
$.getScript({
url: "foo.js",
cache: true
})
jQuery 1.12.0 或更高版本支持
关于javascript - 我可以缓存由 jQuery.getScript() 加载的内容吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30630017/