forked from scandipwa/scandipwa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bringing back the missing README file
- @tilework/opus@0.0.12
- @tilework/opus@0.0.11
- scandipwa-vscode-tools@1.1.0
- scandipwa-vscode-tools@1.0.29
- scandipwa-vscode-tools@1.0.28
- scandipwa-development-toolkit-vscode@1.0.27
- scandipwa-development-toolkit-vscode@1.0.26
- scandipwa-development-toolkit-vscode@1.0.25
- scandipwa-development-toolkit-vscode@1.0.24
- scandipwa-development-toolkit-vscode@1.0.23
- scandipwa-cli@0.4.0
- scandipwa-cli@0.3.21
- scandipwa-cli@0.3.20
- scandipwa-cli@0.3.19
- scandipwa-cli@0.3.18
- scandipwa-cli@0.3.17
- scandipwa-cli@0.3.16
- scandipwa-cli@0.3.15
- scandipwa-cli@0.3.14
- @scandipwa/webpack-i18n-runtime@0.0.33
- @scandipwa/webpack-i18n-runtime@0.0.32
- @scandipwa/webpack-i18n-runtime@0.0.31
- @scandipwa/webpack-i18n-runtime@0.0.30
- @scandipwa/webpack-i18n-runtime@0.0.29
- @scandipwa/webpack-i18n-plugin@0.1.28
- @scandipwa/webpack-i18n-plugin@0.1.27
- @scandipwa/webpack-i18n-plugin@0.1.26
- @scandipwa/webpack-i18n-plugin@0.1.25
- @scandipwa/webpack-i18n-plugin@0.1.24
- @scandipwa/webpack-after-emit-logger@0.0.10
- @scandipwa/webpack-after-emit-logger@0.0.9
- @scandipwa/ts-server-plugin@0.0.4
- @scandipwa/ts-server-plugin@0.0.3
- @scandipwa/stylelint-config@0.0.8
- @scandipwa/stylelint-config@0.0.7
- @scandipwa/stylelint-config@0.0.6
- @scandipwa/stylelint-config@0.0.5
- @scandipwa/stylelint-config@0.0.4
- @scandipwa/stylelint-config@0.0.3
- @scandipwa/stylelint-config@0.0.2
- @scandipwa/service-worker@0.0.18
- @scandipwa/service-worker@0.0.17
- @scandipwa/scandipwa-template-plugin-system@0.1.22
- @scandipwa/scandipwa-template-plugin-system@0.1.21
- @scandipwa/scandipwa-template-plugin-system@0.1.20
- @scandipwa/scandipwa-template-plugin-system@0.1.19
- @scandipwa/scandipwa-template-plugin-system@0.1.18
- @scandipwa/scandipwa-scripts@2.4.23
- @scandipwa/scandipwa-scripts@2.4.22
- @scandipwa/scandipwa-scripts@2.4.21
- @scandipwa/scandipwa-scripts@2.4.20
- @scandipwa/scandipwa-scripts@2.4.19
- @scandipwa/scandipwa-scripts@2.4.18
- @scandipwa/scandipwa-scripts@2.4.17
- @scandipwa/scandipwa-development-toolkit-core@1.1.0
- @scandipwa/scandipwa-development-toolkit-core@1.0.28
- @scandipwa/scandipwa-development-toolkit-core@1.0.27
- @scandipwa/scandipwa-development-toolkit-core@1.0.26
- @scandipwa/scandipwa-development-toolkit-core@1.0.25
- @scandipwa/scandipwa-development-toolkit-core@1.0.24
- @scandipwa/scandipwa-development-toolkit-core@1.0.23
- @scandipwa/scandipwa-dev-utils@0.1.16
- @scandipwa/scandipwa-dev-utils@0.1.15
- @scandipwa/scandipwa-dev-utils@0.1.14
- @scandipwa/scandipwa-dev-utils@0.1.13
- @scandipwa/scandipwa-dev-utils@0.1.12
- @scandipwa/scandipwa@6.0.3
- @scandipwa/scandipwa@6.0.2
- @scandipwa/scandipwa@6.0.1
- @scandipwa/scandipwa@6.0.0
- @scandipwa/scandipwa@5.3.6
- @scandipwa/scandipwa@5.3.5
- @scandipwa/scandipwa@5.3.4
- @scandipwa/scandipwa@5.3.3
- @scandipwa/scandipwa@5.3.2
- @scandipwa/scandipwa@5.3.1
- @scandipwa/scandipwa@5.3.0
- @scandipwa/scandipwa@5.2.7
- @scandipwa/scandipwa@5.2.6
- @scandipwa/scandipwa@5.2.5
- @scandipwa/scandipwa@5.2.4
- @scandipwa/scandipwa@5.2.3
- @scandipwa/scandipwa@5.2.2
- @scandipwa/scandipwa@5.2.1
- @scandipwa/scandipwa@5.2.0
- @scandipwa/scandipwa@5.1.3
- @scandipwa/scandipwa@5.1.2
- @scandipwa/scandipwa@5.1.1
- @scandipwa/scandipwa@5.1.0
- @scandipwa/scandipwa@5.0.7
- @scandipwa/scandipwa@5.0.6
- @scandipwa/scandipwa@5.0.5
- @scandipwa/scandipwa@5.0.4
- @scandipwa/scandipwa@5.0.3
- @scandipwa/scandipwa@5.0.2
- @scandipwa/scandipwa@5.0.1
- @scandipwa/scandipwa@5.0.0
- @scandipwa/scandipwa@4.5.1
- @scandipwa/scandipwa@4.4.0
- @scandipwa/scandipwa@4.3.0
- @scandipwa/scandipwa@4.2.1
- @scandipwa/scandipwa@4.2.0
- @scandipwa/scandipwa@4.1.0
- @scandipwa/scandipwa@4.0.2
- @scandipwa/scandipwa@4.0.1
- @scandipwa/scandipwa@4.0.0
- @scandipwa/scandipwa@3.2.5
- @scandipwa/scandipwa@3.2.4
- @scandipwa/scandipwa@3.2.4-alpha.2
- @scandipwa/scandipwa@3.2.4-alpha.1
- @scandipwa/scandipwa@3.2.4-alpha.0
- @scandipwa/scandipwa@3.2.3
- @scandipwa/router@0.0.9
- @scandipwa/router@0.0.8
- @scandipwa/router@0.0.7
- @scandipwa/router@0.0.6
- @scandipwa/router@0.0.5
- @scandipwa/router@0.0.4
- @scandipwa/router@0.0.3
- @scandipwa/router@0.0.2
- @scandipwa/router@0.0.1
- @scandipwa/postcss-config@0.0.3
- @scandipwa/postcss-config@0.0.2
- @scandipwa/postcss-config@0.0.1
- @scandipwa/next-emulator@0.0.4
- @scandipwa/next-emulator@0.0.3
- @scandipwa/next-emulator@0.0.2
- @scandipwa/m2-theme@0.2.6
- @scandipwa/m2-theme@0.2.5
- @scandipwa/m2-theme@0.2.4
- @scandipwa/m2-theme@0.2.3
- @scandipwa/m2-theme@0.2.2
- @scandipwa/m2-theme@0.2.1
- @scandipwa/m2-theme@0.2.0
- @scandipwa/m2-theme@0.1.6
- @scandipwa/m2-theme@0.1.4
- @scandipwa/m2-theme@0.1.3
- @scandipwa/m2-theme@0.1.2
- @scandipwa/m2-theme@0.1.1
- @scandipwa/m2-theme@0.1.1-alpha.0
- @scandipwa/m2-theme@0.1.0
- @scandipwa/m2-theme@0.0.13
- @scandipwa/m2-theme@0.0.8
- @scandipwa/framework@0.0.11
- @scandipwa/framework@0.0.10
- @scandipwa/framework@0.0.9
- @scandipwa/framework@0.0.8
- @scandipwa/framework@0.0.7
- @scandipwa/framework@0.0.6
- @scandipwa/framework@0.0.5
- @scandipwa/framework@0.0.4
- @scandipwa/framework@0.0.3
- @scandipwa/framework@0.0.2
- @scandipwa/framework@0.0.1
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.38
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.37
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.36
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.35
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.34
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.33
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.32
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.31
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.30
- @scandipwa/eslint-plugin-scandipwa-guidelines@2.0.29
- @scandipwa/eslint-config@0.2.1
- @scandipwa/eslint-config@0.2.0
- @scandipwa/eslint-config@0.1.41
- @scandipwa/eslint-config@0.1.40
- @scandipwa/eslint-config@0.1.39
- @scandipwa/eslint-config@0.1.38
- @scandipwa/eslint-config@0.1.37
- @scandipwa/eslint-config@0.1.36
- @scandipwa/eslint-config@0.1.35
- @scandipwa/eslint-config@0.1.34
- @scandipwa/eslint-config@0.1.33
- @scandipwa/eslint-config@0.1.32
- @scandipwa/csa-generator-theme@0.4.4
- @scandipwa/csa-generator-theme@0.4.3
- @scandipwa/csa-generator-theme@0.4.2
- @scandipwa/csa-generator-theme@0.4.1
- @scandipwa/csa-generator-theme@0.4.0
- @scandipwa/csa-generator-theme@0.3.4
- @scandipwa/csa-generator-theme@0.3.3
- @scandipwa/csa-generator-theme@0.3.2
- @scandipwa/csa-generator-theme@0.3.1
- @scandipwa/csa-generator-theme@0.3.0
- @scandipwa/csa-generator-theme@0.2.25
- @scandipwa/csa-generator-theme@0.2.24
- @scandipwa/csa-generator-theme@0.2.23
- @scandipwa/csa-generator-extension@0.0.26
- @scandipwa/csa-generator-extension@0.0.25
- @scandipwa/csa-generator-cra@0.1.23
- @scandipwa/csa-generator-cra@0.1.22
- @scandipwa/csa-generator-cra@0.1.21
- @scandipwa/csa-generator-cra@0.1.20
- @scandipwa/csa-generator-cra@0.1.19
- @scandipwa/csa-generator-blank@0.1.23
- @scandipwa/csa-generator-blank@0.1.22
- @scandipwa/csa-generator-blank@0.1.21
- @scandipwa/csa-generator-blank@0.1.20
- @scandipwa/csa-generator-blank@0.1.19
- @scandipwa/chunk-optimizer@0.0.9
- @scandipwa/chunk-optimizer@0.0.8
- @scandipwa/chunk-optimizer@0.0.7
- @scandipwa/chunk-optimizer@0.0.6
- @scandipwa/chunk-optimizer@0.0.5
- @scandipwa/chunk-optimizer@0.0.4
- @scandipwa/chunk-optimizer@0.0.3
- @scandipwa/chunk-optimizer@0.0.2
- @scandipwa/bundle-analyzer@0.0.9
- @scandipwa/bundle-analyzer@0.0.8
- @scandipwa/bundle-analyzer@0.0.7
- @scandipwa/bundle-analyzer@0.0.6
- @scandipwa/bundle-analyzer@0.0.5
- @scandipwa/bundle-analyzer@0.0.4
- create-scandipwa-app@1.4.9
- create-scandipwa-app@1.4.8
- create-scandipwa-app@1.4.7
- create-scandipwa-app@1.4.6
- create-scandipwa-app@1.4.5
- create-scandipwa-app@1.4.4
- create-scandipwa-app@1.4.3
- create-scandipwa-app@1.4.2
- create-scandipwa-app@1.4.1
- create-scandipwa-app@1.4.0
- create-scandipwa-app@1.3.22
- create-scandipwa-app@1.3.21
- create-scandipwa-app@1.3.20
1 parent
1fe781a
commit 9bd34ed
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Scandiweb PWA serviceworker | ||
|
||
The repository is a Service Worker script and a dev environment for it. | ||
|
||
## Features | ||
- Google's `workbox` is used as base: (`core`, `routing`, `strategies`, `cache-expiration`). | ||
- Custom implementation for POST requests, implemented on top of IndexedDB. | ||
- Cache flush from application slide (including mass flush) | ||
- Cache flush using serverside config | ||
- Forward data after revalidation in staleWhileRevalidate POST strategy | ||
|
||
### main.js | ||
Entrypoint for service worker, includes helper methods and route definitions along with the handlers. | ||
|
||
### Handlers | ||
Apart of `PostCacheHandler` there are all workbox cache strategies available withing `src/handlers.js` for | ||
convenience. Remember to export anything you need/create and define route handler within main.js | ||
|
||
Out of the box there are few routes predefined: | ||
`/graphql`, `/graphemulate` - for testing and developing POST caching | ||
`/flush-cache` - allows clear entire cache/single resource within the *runtime* cache | ||
`/media` - so you can take a look how your frontend can work without a connection/during server downtime | ||
|
||
### POST caching | ||
Post caching is based on IndexedDB, that stores Request Body hash and corresponding Response Body. | ||
Currently, it has one strategy, the name was borrowed/corresponds with Google's Workbox handler | ||
`staleWhileRevalidate`, however, it provides additional possibility to set cached data TTL before an attempt of | ||
revalidation will be made. | ||
|
||
Cache data will be served in any case, whether available, however revalidation happens after `SW-Cache-Age` expiration (default: `0`). | ||
|
||
### Cache flush | ||
Any cache item can be removed/entire cache storage flushed with a simple Request from an application: | ||
Craete a Request and send it to `/flush-cache`, adding custom header `Cache-purge` with *Resource* name. | ||
|
||
##### Resource can be any resource name (starting with `/`), or Cache storage name, without any prefix. | ||
|
||
An example: delete `/styles.css` from Cache storage: | ||
``` | ||
fetch('/flush-cache', { | ||
method: 'GET', | ||
headers: { | ||
'Cache-purge': '/styles.css', | ||
} | ||
``` | ||
|
||
An example: flush all cached items within `runtime-static` Cache | ||
``` | ||
fetch('/flush-cache', { | ||
method: 'GET', | ||
headers: { | ||
'Cache-purge': 'runtime-static', | ||
} | ||
``` | ||
|
||
### Data revalidation and update | ||
Any time, when POST method is handled with staleWhileRevalidate it immediately returns cached data (whether | ||
available) and initialize data update after `SW-Cache-Age` ends. | ||
Since service worker can not interact with DOM in any way, on update Response it saves data to cache and initializes | ||
Broadcast API channel, according to `Application-Model` header value. | ||
|
||
An example: | ||
``` | ||
fetch('/graphemulate', { | ||
method: 'post', | ||
headers: { | ||
... | ||
'Application-Model': 'Product', | ||
'SW-Cache': '60', | ||
}, | ||
body: JSON.stringify({...}), | ||
``` | ||
|
||
When update Response is received, handler will create a Broadcast Channel and post updated Response body there: | ||
``` | ||
... | ||
const bc = new BroadcastChannel(appModel) // appModel = 'Product'; | ||
bc.postMessage({ payload: body, type: appModel }); | ||
``` | ||
|
||
Which can be catched with Product model: | ||
``` | ||
const updatesChannel = new BroadcastChannel('Product'); | ||
updatesChannel.addEventListener('message', (event) => { | ||
console.log('Event was triggered'); | ||
console.log(event.data.payload); | ||
console.log('APPLICATION: RESPONSE: ', event.data); | ||
document.getElementById('response').value = JSON.stringify(event.data.payload) + ' +updated'; | ||
}); | ||
``` | ||
|
||
### Offline mode | ||
|
||
Any cached resource or data will be still available even server/network is not available. | ||
Additionally, when Service Worker attempts to revalidate data, as soon, as `fetch()` failes it opens | ||
`network-error` Broadcast Channel and passes an object there: | ||
- `offline` :bool - true or false, indicate whether client/server is offline (when true) | ||
- `message` :string - can be used for showing to customer/debugging, as other Service Worker issues (like Response | ||
body JSON parse fail) will be communicated over this channel as well. |