Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

[exp] pwa #152

Merged
merged 5 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"scripts": {
"start": "craco start",
"build": "craco build",
"build": "craco build && sw-precache-cra --config sw-config.js",
"test": "craco test",
"eject": "craco eject"
},
Expand Down
2 changes: 1 addition & 1 deletion web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ReactDOM.render(
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://cra.link/PWA
serviceWorkerRegistration.unregister()
serviceWorkerRegistration.register()

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
Expand Down
4 changes: 4 additions & 0 deletions web/src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ registerRoute(
return false
}

if (url.pathname.match(/\/api\/.*/gi)) {
return false
}

// Return true to signal that we want to use the handler.
return true
},
Expand Down
15 changes: 14 additions & 1 deletion web/sw-config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
module.exports = {
navigateFallbackWhitelist: [/^(?!.*\/api\/).*/],
runtimeCaching: [
{
urlPattern: /^(.*\/api\/).*$/,
urlPattern: '/api/',
handler: 'networkFirst',
},
{
urlPattern: '/view',
handler: 'networkFirst',
},
// {
// urlPattern: '/dashboard',
// handler: 'networkFirst',
// },
// {
// urlPattern: /^(.*\/api\/).*$|^(.*\/dashboard).*$|^(.*\/view).*$/,
// handler: 'networkFirst',
// },
// {
// urlPattern: /^(?!.*\/api\/).*$/,
// handler: 'fastest',
Expand Down