LeeTee
LeeTee

Reputation: 6601

Node Webkit Desktop App - Browser default caching of PDF files

I have built a desktop app using node webkit and need to cache PDF files that are viewed via the App when online so that they are also available offline. I haven't found a solution yet but during testing I noticed that files that I had previously viewed online were available offline even though I haven't written any code for this yet. Therefore these must already be cached automatically. I did a search to find where the files are being saved exactly but couldn't find anything.

Can anyone explain this or point me in the direction of information on this so that I understand how it works and ensure my App can utilise the default behaviour of the browser caching?

********UPDATE***********

I have found a solution to store the PDFs locally, however this isn't my query. I am looking for an explanation as to HOW the PDFs are available when offline without this code I have written. The files must be automatically be stored somewhere otherwise how would they display?

Upvotes: 4

Views: 237

Answers (2)

Technologeek
Technologeek

Reputation: 190

The default location to cache your app files is mentioned in your package.json manifest file.When the app is initialized the settings in your manifest files are loaded by default.Since cached files cannot be accessed programmatically,you can overwrite the default files manually.

To get the application’s data path in user’s directory for windows,you can write it in Jason format in your package :

Windows: %LOCALAPPDATA%/

You can read about other cache menthods in node webkit's documentation : http://docs.nwjs.io/en/latest/References/App/#appclearcache

Upvotes: 0

KeatsPeeks
KeatsPeeks

Reputation: 19337

The default caching behavior of node-webkit is controlled by the page-cache property in package.json :

 "webkit": {
     "page-cache": true
 },

Only typical web resources can be cached this way (scripts, style sheets, etc.). To be able to view PDF files offline, you can store them manually.

There are several ways to do that :

  • Save a file directly to disk (the simple solution, just store the files in App.dataPath)
  • Use a database
  • Use Web Storage
  • Use the application cache

All of these are documented here : Save persistent data in app

Upvotes: 1

Related Questions