sp-dev-fx-webparts/samples/react-offline-first
Hugo Bernier 103907bdc6 Added compatibility warning on readme and template 2023-02-10 10:22:32 -05:00
..
.devcontainer added remaining containers 2022-02-16 21:47:07 -05:00
assets Changed docs links to learn 2022-10-24 09:42:45 -04:00
config
src/webparts/reactOfflineFirst
.editorconfig
.gitignore
.yo-rc.json
README.md Added compatibility warning on readme and template 2023-02-10 10:22:32 -05:00
gulpfile.js
package-lock.json
package.json
tsconfig.json
tslint.json

README.md

page_type products languages extensions
sample
office-sp
javascript
typescript
contentType technologies platforms createdDate
samples
SharePoint Framework
react
3/1/2018 12:00:00 AM

Offline First using LocalForage, Whatwg-Fetch, ES6-Promise

Summary

Sample Web part that demonstrates how to use offline storage in a way that is more offline first.

This web part would not be possible without the great tools provided, please read the documentation for

Sample of the offline first web part

Compatibility

⚠️ Important
Every SPFx version is only compatible with specific version(s) of Node.js. In order to be able to build this sample, please ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node.
Refer to https://aka.ms/spfx-matrix for more information on SPFx compatibility.

SPFx 1.4.1 Node.js v6 | v8 Compatible with SharePoint Online Compatible SharePoint 2019 Does not work with SharePoint 2016 (Feature Pack 2) Local Workbench Compatible Hosted Workbench Compatible Compatible with Remote Containers

Applies to

Solution

Solution Author(s)
react-offline-first Austin Breslin

Version history

Version Date Comments
0.0.1 17/Feb/18 Got the HTTP Requests to work.
0.0.2 17/Feb/18 Separated interfaces into their own files.
0.0.3 18/Feb/18 Updated JSDocs, and and created readme.

Minimal Path to Awesome

  • Clone this repo
  • In the command line run:
    • npm install
    • tsd install
    • gulp serve
    • Open the workbench on your Office 365 Developer tenant
    • Test out the web part

This sample can also be opened with VS Code Remote Development. Visit https://aka.ms/spfx-devcontainer for further instructions.

Features

This web part demonstrates using the OfflineFirstHTTPService how to do offline first HTTP Requests.

HTTP Get requests are first retrieved from an offline storage system. Either localStorage, IndexedDB, WebSQL or SessionStorage, but maybe not in that order. Then the live request is using fetch, then stored locally, errors are placed into a queue for when available.

HTTP Posts/Updates/Deletes are executed differently to GET requests, they always make a HTTP request using fetch, but on failure are added to the queue.

The Queue system collects all failed HTTP Requests and when the user is online will try to make the requests again, all requests are async so will not cause any blocking for the user.

This Web Part illustrates the following concepts on top of the SharePoint Framework:

  • Using offline first techniques, store locally, retrieve locally before making HTTP requests.
  • Async looping, can be found in the Queue System.
  • Performance techniques for browsers, async looping does not block render, using local storage first reduces the time to draw the initial page load.

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.