jQuery Pre-load Not Caching in Chrome or Safari

回眸只為那壹抹淺笑 提交于 2019-12-24 20:33:08

问题


I have a jquery slideshow and built a pre-load function:

function preload_images(){
var pre_image = curr_img - 1;
if(pre_image < 0) pre_image = (tot_elements-1);

var curr_obj = 0;

if(!$('#img_preloaded_'+pre_image).length > 0){
    curr_obj = slideshow[pre_image];
    $('.preload_left').append('<img src="'+curr_obj["img_url"]+'" id="img_preloaded_'+pre_image+'" class="preload_box" />');
}

var pre_image = curr_img + 1;
if(tot_elements==pre_image) pre_image = 0;
if(!$('#img_preloaded_'+pre_image).length > 0){
    curr_obj = slideshow[pre_image];
    $('.preload_right').append('<img src="'+curr_obj["img_url"]+'" id="img_preloaded_'+pre_image+'" class="preload_box" />');
}

Everything works great in Firefox - images are cached when loaded - but the images are not cached in Chrome or Safari for some reason. You can see that in FF, Chrome and Safari the images load into the document to the left of the slideshow, but they don't cache. The slideshow re-loads them except for in FF because the image is already cached in FF.

https://www.assembla.com/code/cfrepo/subversion/node/blob/trunk/index.html#image=CrossFire http://jsfiddle.net/doobada/9m9eq/

Any thoughts?


回答1:


Ok, it looks like Chrome and other browsers have their own default for cache-expires. To fix this problem I needed to pre-load the images in the slideshow set and then change the expires. It was only working in Firefox properly until I edited the .htaccess file so that chrome does not give it's default expiry:

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Expires "Thu, 15 Jan 2015 20:00:00 GMT" </FilesMatch>


来源:https://stackoverflow.com/questions/13182358/jquery-pre-load-not-caching-in-chrome-or-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!