perf(PWA): Use Network-only strategy for service worker (#1468)

This commit is contained in:
Rémi Marseault 2024-01-20 15:46:08 +01:00 committed by GitHub
parent cf07601f8c
commit f4842c4444
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 108 additions and 3720 deletions

View file

@ -13,6 +13,10 @@
<link rel="apple-touch-icon" href="/apple-touch-icon.png" /> <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<meta name="theme-color" content="#000" /> <meta name="theme-color" content="#000" />
<title>VueTorrent</title> <title>VueTorrent</title>
<!-- PWA setup -->
<link rel="manifest" href="/manifest.webmanifest" crossorigin="use-credentials">
<script src="/registerSW.js"></script>
</head> </head>
<body> <body>
<noscript> <noscript>

3773
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -28,7 +28,6 @@
"pinia": "^2.1.6", "pinia": "^2.1.6",
"pinia-plugin-persist": "^1.0.0", "pinia-plugin-persist": "^1.0.0",
"uuid": "^9.0.1", "uuid": "^9.0.1",
"vite-plugin-pwa": "^0.17.4",
"vite-plugin-vuetify": "^2.0.1", "vite-plugin-vuetify": "^2.0.1",
"vue": "^3.4.14", "vue": "^3.4.14",
"vue-i18n": "^9.9.0", "vue-i18n": "^9.9.0",

View file

@ -0,0 +1,22 @@
{
"name": "VueTorrent",
"short_name": "VueTorrent",
"start_url": ".",
"display": "standalone",
"background_color": "#000",
"lang": "en",
"scope": "./",
"theme_color": "#597566",
"icons": [
{
"src": "./icon-192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "./icon-512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}

1
public/registerSW.js Normal file
View file

@ -0,0 +1 @@
"serviceWorker"in navigator&&window.addEventListener("load",(async()=>{await navigator.serviceWorker.register("/sw.js")}));

1
public/sw.js Normal file
View file

@ -0,0 +1 @@
self.addEventListener("install",(()=>{})),self.addEventListener("fetch",(()=>{}));

View file

@ -3,7 +3,6 @@ import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url' import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite' import { defineConfig, loadEnv } from 'vite'
import vuetify from 'vite-plugin-vuetify' import vuetify from 'vite-plugin-vuetify'
import { VitePWA } from 'vite-plugin-pwa'
import { resolve } from 'node:path' import { resolve } from 'node:path'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
@ -33,30 +32,7 @@ export default defineConfig(({ mode }) => {
}, },
plugins: [ plugins: [
vue(), vue(),
vuetify(), vuetify()
VitePWA({
includeAssets: ['favicon.ico', 'icon.svg', 'icon-192.png', 'icon-512.png', 'robots.txt'],
manifest: {
name: 'VueTorrent',
short_name: 'VueTorrent',
theme_color: '#597566',
start_url: '.',
background_color: '#000',
icons: [
{ src: './icon-192.png', type: 'image/png', sizes: '192x192' },
{ src: './icon-512.png', type: 'image/png', sizes: '512x512' }
]
},
// Other options
registerType: 'autoUpdate',
base: './',
useCredentials: true,
workbox: {
maximumFileSizeToCacheInBytes: 10_000_000,
skipWaiting: true,
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff,woff2}']
}
})
], ],
publicDir: './public', publicDir: './public',
resolve: { resolve: {