Skip to content

Commit 5086bd0

Browse files
committedAug 16, 2022
chore!: remove service worker altogether
it was just too complicated
1 parent 3beee02 commit 5086bd0

20 files changed

+25
-559
lines changed
 

‎.env.development.example

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ KIRBY_DEV_PORT=8080
88
KIRBY_DEV_PROTOCOL=http
99
VITE_DEV_PORT=3000
1010

11-
VITE_SERVICE_WORKER=false
1211
VITE_STALE_WHILE_REVALIDATE=false
1312

1413
# API slug to fetch JSON-encoded page data from

‎.env.production.example

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ KIRBY_DEV_PORT=8080
88
KIRBY_DEV_PROTOCOL=http
99
VITE_DEV_PORT=3000
1010

11-
VITE_SERVICE_WORKER=false
1211
VITE_STALE_WHILE_REVALIDATE=false
1312

1413
# API slug to fetch JSON-encoded page data from
174 KB
Loading

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ vendor
2222
# Build assets
2323
/public/assets
2424
/public/dist
25-
/public/service-worker.js

‎README.md

+3-30
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
- 🔍 SEO-friendly: [server-side generated](https://github.com/johannschopplich/kirby-extended/blob/main/docs/meta.md) meta tags
2323
- 🌐 [Multi-language](#multi-language) support
2424
- ♿ Accessible frontend routing
25-
- 🚝 [Offline-first](#caching--offline-capability-with-service-worker)
2625
- 💫 [Stale-while-revalidate](#stale-while-revalidate) page data
2726

2827
## Alternatives
@@ -60,12 +59,6 @@ kirby-vue3-starterkit/
6059
| | # Kirby's media folder for thumbnails and more (not tracked by Git)
6160
| └── media/
6261
|
63-
| # Various development-related Node scripts
64-
├── scripts/
65-
| |
66-
| | # Service worker generator (optional)
67-
| └── buildServiceWorker.js
68-
|
6962
| # Kirby's core folder containing templates, blueprints, etc.
7063
├── site/
7164
| ├── config/
@@ -116,9 +109,6 @@ kirby-vue3-starterkit/
116109
| | | # Returns page data for the current path, similarly to Kirby's `$page` object
117110
| | ├── usePage.js
118111
| | |
119-
| | | # Various service worker methods like registering
120-
| | ├── useServiceWorker.js
121-
| | |
122112
| | | # Returns a object corresponding to Kirby's global `$site`
123113
| | └── useSite.js
124114
| |
@@ -137,8 +127,7 @@ kirby-vue3-starterkit/
137127
| |
138128
| ├── App.vue
139129
| ├── index.css
140-
| ├── index.js
141-
| └── serviceWorker.js
130+
| └── index.js
142131
|
143132
| # Contains everything content and user data related (not tracked by Git)
144133
├── storage/
@@ -160,20 +149,12 @@ kirby-vue3-starterkit/
160149

161150
</details>
162151

163-
## Caching & Offline Capability With Service Worker
152+
## Caching
164153

165-
Even without a service worker installed, the frontend will store pages between individual routes/views. When the tab get reloaded, the data for each page is freshly fetched from the API once again.
166-
167-
For offline capability of your Vue app, you can choose to activate the included [service worker](src/serviceWorker.js).
168-
169-
A visual explanation of both methods can be found in the following flow chart:
154+
The frontend will store pages between individual routes/views. When the tab get reloaded, the data for each page is freshly fetched from the API once again.
170155

171156
![Caching for Kirby and Vue 3 starterkit](./.github/kirby-vue-3-cache-and-store.png)
172157

173-
The service worker precaches all CSS & JS assets required by the Vue app and caches the data of every requested page. All assets are versioned and served from the service worker cache directly.
174-
175-
Each JSON request will be freshly fetched from the network and saved to the cache. If the user's navigator turns out to be offline, the cached page request will be returned.
176-
177158
## Stale-While-Revalidate
178159

179160
The stale-while-revalidate mechanism for the [`usePage`](src/composables/usePage.js) hook allows you to respond as quickly as possible with cached page data if available, falling back to the network request if it's not cached. The network request is then used to update the cached page data – which directly affects the view after lazily assigning changes (if any), thanks to Vue's reactivity.
@@ -292,14 +273,6 @@ Then, visit the panel and add new languages by your liking. The Panel **automati
292273

293274
Language data is provided by the global `site` object, which can be accessed via the `useSite()` hook.
294275

295-
### Service Worker
296-
297-
To enable the **service worker** which precaches essential assets and page API calls for offline capability, set:
298-
299-
- `VITE_SERVICE_WORKER` to `true`
300-
301-
> ⚠️ Don't change the `CONTENT_API_SLUG` once you deployed your app publicly and thus a service worker is installed on clients. Otherwise fetch requests will fail and a blank page will show until the new service worker is activated, which then is only possible by closing the tab/PWA.
302-
303276
### Stale-While-Revalidating
304277

305278
To keep page data fresh with **stale-while-revalidate**, set:

‎package-lock.json

+14-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"kirby": "env-cmd --use-shell \"php -S \\$KIRBY_DEV_HOSTNAME:\\$KIRBY_DEV_PORT -t public vendor/getkirby/cms/router.php\"",
66
"dev": "shx touch src/.lock && concurrently \"npm:kirby\" \"vite\"",
7-
"build": "shx rm -f src/.lock && vite build && node scripts/buildServiceWorker.mjs",
7+
"build": "shx rm -f src/.lock && vite build",
88
"lint": "eslint \"src/**/*.{js,vue}\"",
99
"lint:fix": "npm run lint -- --fix",
1010
"format": "prettier --write \"src/**/*.{js,vue}\""
@@ -19,13 +19,11 @@
1919
"@types/node": "^18.7.4",
2020
"@vitejs/plugin-vue": "^3.0.3",
2121
"concurrently": "^7.3.0",
22-
"consola": "^2.15.3",
2322
"dotenv": "^16.0.1",
2423
"env-cmd": "^10.1.0",
2524
"eslint": "^8.22.0",
2625
"eslint-config-prettier": "^8.5.0",
2726
"eslint-plugin-vue": "^9.3.0",
28-
"nanoid": "^4.0.0",
2927
"prettier": "2.7.1",
3028
"shx": "^0.3.4",
3129
"unplugin-vue-components": "^0.22.4",

‎scripts/buildServiceWorker.mjs

-36
This file was deleted.

‎src/App.vue

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</main>
1010
</div>
1111

12-
<UpdateNotification />
1312
<Footer />
1413
</template>
1514

‎src/components/Footer.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useSite } from "~/composables";
1818
const site = useSite();
1919
</script>
2020

21-
<style>
21+
<style scoped>
2222
.footer {
2323
padding: 1.5rem 5vw 10vh;
2424
text-align: center;

‎src/components/Header.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const site = useSite();
2727
const route = useRoute();
2828
</script>
2929

30-
<style>
30+
<style scoped>
3131
.header {
3232
margin-bottom: 1.5rem;
3333
}

‎src/components/Intro.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</header>
77
</template>
88

9-
<style>
9+
<style scoped>
1010
.intro {
1111
padding: 10vh 0;
1212
text-align: center;

‎src/components/SkipToContentLink.vue

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<template>
2-
<a
3-
ref="skipLink"
4-
href="#main"
5-
class="skip-to-content-link"
6-
@click.prevent="navigate()"
7-
>
2+
<a ref="skipLink" href="#main" class="skip-link" @click.prevent="navigate()">
83
Skip to content
94
</a>
105
</template>
@@ -30,15 +25,15 @@ function navigate({ target }) {
3025
}
3126
</script>
3227
33-
<style>
34-
.skip-to-content-link {
28+
<style scoped>
29+
.skip-link {
3530
position: absolute;
3631
top: 0;
3732
left: 50%;
3833
padding: 0.5rem;
3934
transform: translate(-50%, -100%);
4035
}
41-
.skip-to-content-link:focus {
36+
.skip-link:focus {
4237
transform: translate(-50%, 0);
4338
/* Copy the browser's native focus styles */
4439
outline: 5px auto Highlight;

‎src/components/UpdateNotification.vue

-41
This file was deleted.

‎src/composables/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ export { default as useAnnouncer } from "./useAnnouncer";
22
export { default as useKirbyApi } from "./useKirbyApi";
33
export { default as useLanguages } from "./useLanguages";
44
export { default as usePage } from "./usePage";
5-
export { default as useServiceWorker } from "./useServiceWorker";
65
export { default as useSite } from "./useSite";

‎src/composables/usePage.js

-9
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ export default (path) => {
5454
router.replace({ path: "/error" });
5555
return;
5656
}
57-
58-
// Redirect to offline page if page hasn't been cached either in-store or
59-
// by the service worker and the offline fallback JSON was returned
60-
// Note: data for `home` and `offline` pages are always available since they
61-
// are precached by the service worker
62-
if (data.__isOffline) {
63-
router.replace({ path: "/offline" });
64-
return;
65-
}
6657
}
6758

6859
// Append page data to reactive page object

‎src/composables/useServiceWorker.js

-183
This file was deleted.

‎src/main.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createApp } from "vue";
2-
import { useServiceWorker } from "./composables";
32
import App from "./App.vue";
43
import "./styles/main.css";
54

@@ -12,6 +11,3 @@ for (const m of Object.values(
1211
}
1312

1413
app.mount("#app");
15-
16-
const { initSw } = useServiceWorker();
17-
initSw();

‎src/serviceWorker.js

-171
This file was deleted.

‎storage/content/offline/default.txt

-17
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.