How can I cache image files locally with PhoneGap / Cordova?

After long hours searching on SO and Github, I found imgCache.js, a JS library that handle file cache for Chrome, Android and iOs (through Cordova).

https://github.com/chrisben/imgcache.js/

Then, basically :

var target = $('.cached-img');

ImgCache.isCached(target.attr('src'), function(path, success){
          if(success){
            // already cached
            ImgCache.useCachedFile(target);
          } else {
            // not there, need to cache the image
            ImgCache.cacheFile(target.attr('src'), function(){
              ImgCache.useCachedFile(target);
            });
          }
        });

Leave a Comment