samedi 28 mars 2015

How to load an image from cache using PhoneGap

Today I was trying to add the library "imgcache" by Chrisben, but I can't make it work.



// write log to console
ImgCache.options.debug = true;

// increase allocated space on Chrome to 50MB, default was 10MB
ImgCache.options.chromeQuota = 50*1024*1024;

ImgCache.init(function(){
alert('ImgCache init: success!');

var target = $('#logo');
ImgCache.isCached(target.attr('src'), function(path, success) {
if (success) {
console.log("already cached!");
// already cached
ImgCache.useCachedFile(target);
} else {
console.log("cache the image and show!");
// not there, need to cache the image
ImgCache.cacheFile(target.attr('src'), function () {
ImgCache.useCachedFile(target);
});
}
});
}, function(){
alert('ImgCache init: error! Check the log for errors');
});


Can someone help me? Why isn't this working? On load it works, but if I click on the "Back" button, then the image should open by cache, but I only see an icon that the image can not be found.


Aucun commentaire:

Enregistrer un commentaire