在Chrome或Safari中jQuery Pre-load Not Caching [英] jQuery Pre-load Not Caching in Chrome or Safari

查看:89
本文介绍了在Chrome或Safari中jQuery Pre-load Not Caching的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery幻灯片并构建了一个预加载函数:

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

var curr_obj = 0; $!
$ b if(!$('#img_preloaded _'+ pre_image).length> 0){
curr_obj =幻灯片[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 =幻灯片[pre_image];
$('。preload_right')。append('< img src =''+ curr_obj [img_url] +'id =img_preloaded _'+ pre_image +'class =preload_box/>' );
}

在Firefox中一切正常 - 图像在加载时被缓存 - 但图像是出于某种原因,未在Chrome或Safari中缓存。您可以看到,在FF,Chrome和Safari中,图像加载到幻灯片左侧的文档中,但它们不缓存。幻灯片重新加载它们,除了FF以外,因为图像已经缓存在FF中。



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

有什么想法?


好的,Chrome浏览器和其他浏览器对于cache-expires有自己的默认设置。为了解决这个问题,我需要预先加载幻灯片集中的图像,然后更改过期。它只在Firefox中正常工作,直到我编辑.htaccess文件,以便chrome不会使其默认到期:

 < FilesMatch\。(ico | pdf | flv | jpg | jpeg | png | gif | js | css | swf)$>标题集过期时间2014年1月15日星期四20:00:00 GMT< / FilesMatch> 


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?

解决方案

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>

这篇关于在Chrome或Safari中jQuery Pre-load Not Caching的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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