Saving requests for later

So far, we've learned how to intercept requests and either return or even enhance the response from our local system. Now, we will learn how to save requests when we are in offline mode and then send the calls to the server once we appear online.

Let's go ahead and set up a new folder for just this. Follow these steps:

  1. Create a folder called offline_storage and add the following files to it:
  • index.html
  • main.css
  • interactions.js
  • OfflineServiceWorker.js
  1. Add the following boilerplate code to index.html:
<!DOCTYPE html><html>    <head><!-- add css file --></head>    <body>        <h1>Offline Storage</h1>        <button id="makeRequest">Request</button>        <table>            <tbody id="body"></tbody>        </table> <p>Are we online?: <span id="online">No</span> ...

Get Hands-On JavaScript High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.