Configure Data Cache and Offline Support

Use the Oracle Offline Persistence Toolkit to enable data caching and offline support within your Oracle JET app.

About the Oracle Offline Persistence Toolkit

The toolkit is a client-side JavaScript library that Oracle maintains as an open-source project. The toolkit provides caching and offline support at the HTTP request layer.

This support is transparent to the user and is done through the Fetch API and an XHR adapter. HTTP requests made while the client or client device is offline are captured for replay when connection to the server is restored. Additional capabilities include a persistent storage layer, synchronization manager, binary data support and various configuration APIs for customizing the default behavior. This toolkit can be used in both ServiceWorker and non-ServiceWorker contexts within web apps.

Using the toolkit, you can configure your app to:

The architecture diagram illustrates the major components of the toolkit and how an app interacts with it.

Here’s a concise and accessible alt text for the image:

**Alt text:**  
A flowchart diagram illustrating the architecture of an offline persistence toolkit for a web application. It shows the interaction between the Application layer (with actions like Get, Put, Delete, Post, Patch), the Offline Persistence Toolkit (including Persistent Storage, Binary Data Support, and components like Fetch API, XHR Adapter, and Event Listener), and the Sync Manager. The diagram also depicts the flow of HTTP requests and REST JSON responses between the client and server-side resources, including Web Services (REST).

Description of the illustration persistence-framework.png

Install the Offline Persistence Toolkit

Use npm to install the offline persistence toolkit. After installation, you must update your application’s src/js/path_mapping.json file to recognize the new package.

  1. Change to your application's top level directory and open a terminal window.

  2. At the terminal prompt, enter the following command to install the toolkit: npm install @oracle/offline-persistence-toolkit --save.

  3. Change to your app's src/js directory and open path_mapping.json for editing.

  4. Add the persistence toolkit to the "libs" entry.

    The easiest way to add the toolkit is to copy an existing entry that's similar to your library and modify as needed. A sample entry for offline-persistence-toolkit, which started with a copy of the "ojs" entry, is shown below.

    "libs": {
    
        "offline-persistence-toolkit": {
          "cdn": "",
          "cwd": "node_modules/@oracle/offline-persistence-toolkit/dist",
          "debug": {
            "cwd": "debug",
            "src": [""],
            "path": "libs/offline-persistence-toolkit/debug",
            "cdn": ""
          },
          "release": {
            "cwd": "min",
            "src": [""],
            "path": "libs/offline-persistence-toolkit/min",
            "cdn": ""
          }
    },

For information about using the toolkit once you have it installed in your Oracle JET app, see the README.md and Wiki for the persistence toolkit on Github at https://github.com/oracle/offline-persistence-toolkit.