imgcache.js
imgcache.js copied to clipboard
Ability to load local file directly to cache (precache)
This is a request for a new feature in imgcache.js to support loading a local file directly into the cache. At present, it appears that the the only way to load a file into the cache is by remotely downloading this file.
I am developing a Cordova-based app, intended to run on Android and iOS, which starts out with a image slider that switches images every 5 seconds. I would like to pre-cache the first two images in this slider, as this will allow the app to start right away, and provide 10 seconds at app startup when the remote images can be downloaded in the background, before being displayed.
While there are several workaround strategies, none of them seem quite as clean as preloading the cache.
As I see it, there are two approaches for this.
- Add a new API entry point, ImgCache.preloadCache() that will take a file and write it into the cache.
- Alter ImgCache.cacheFile() such that it accepts files and http(s) URLs.
Thank you for considering this feature enhancement, and for your work so far on imgcache.js!
I'm willing to take a stab at writing this myself, but I'm concerned that I don't have as rich an understanding of the cross-platform environment as you.
:+1:
@JimWhiteheadUCSC If you really need to do this, I created a solution that works for me. I have to manually inject two lines into imgcache.js to make things "public" for me to use but here is the gist - https://gist.github.com/joshdholtz/33871e08e2fd83ea1b62
Example use ImgCache.cacheLocalFile('your_image_key', mergedImageData, function() { console.log("success"); }, function() { console.log("failure"); });
NOTE: I have not made a pull request with these changes yet since I just got them working about 30 minutes ago. I want to run with this for a bit to make sure if fully works before I get a pull request made for this.
I'm not really sure I see the point of caching files that already stored locally apart from simplifying your front-end code to just deal with cached files instead of local and cached files. Anyway I set this issue as an enhancement.
Thanks @joshdholtz for your help there.