Reputation: 1418
I have a node-webkit desktop application that displays tons of images on some pages. I'd like to ask node-webkit to cache all incoming images like browser do. Is there a way to do this?
I can write a simple caching mechanism (download those images and store them locally) but suppose that there is a native way for it.
Upvotes: 0
Views: 948
Reputation: 186
I am working on a similar issue. It appears that we have access to webkit's page cache, but it is defaulted to disabled. In package.json you would have to add:
"webkit": { // (object) controls what features of WebKit should be on/off.
"plugin": false, // (boolean) whether to load external browser plugins like Flash, default to false.
"java": false, // (boolean) whether to load Java applets, default to false.
"page-cache": true // (boolean) whether to enable page cache, default to false. }
Given that you have turned the page-cache on you must also manage clearing the cache as there would be no mechanism for the end user to clear it themselves unless you provide it. So you would at some point either programmatically or by user input need to call:
// Load native UI library
var gui = require('nw.gui');
// Clear the HTTP cache in memory and on disk. This method call is synchronized.
gui.App.clearCache();
*I haven't run the code and in another post I see that there may be some problem with the clearCache() method, so a way of handling this manually is suggested Node Webkit clear cache
Upvotes: 1