但是针对缓存这事,一个是在服务端设置,也就少web服务或者少CDN那设置缓存。很多情况下,图片,css都是默认缓存的,你打开开发者工具之后确保禁用缓存的复选框取消,你刷新一下,看看那图片、css是不是就是304状态。
jquery自从1.2开始就有ifModified和cache参数了,不用自己加headerifModified Boolean Default: false
Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is false, ignoring the header.
cache Boolean Default: true
Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
cache:false,
ifModified :true
})
alert('该图片已经存在于缓存之中,不会再去重新下载')}else{alert('图片不存在缓存之中')alert('图片下载成功!')}}shiyong使用Image对象的complete属性来判断指定图片是否已经存在缓存之中,当complete属性为true是该图片则已经存在于缓存之中,否则反之。