Add support for desktop PWA

This commit is contained in:
Phan An 2019-03-13 08:21:56 +01:00
parent 433586e1ac
commit 1782f8910a
3 changed files with 21 additions and 2 deletions

View file

@ -16,7 +16,7 @@
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Whitelist only index.php, robots.txt, and some special routes
RewriteRule ^(?!($|index\.php|robots\.txt|(public|api)/|remote|api-docs)) - [R=404,L]
RewriteRule ^(?!($|index\.php|robots\.txt|(public|api)/|remote|api-docs|sw\.js)) - [R=404,L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d

View file

@ -2,7 +2,7 @@
"name": "Koel",
"start_url": "/",
"display": "standalone",
"orientation": "portrait",
"orientation": "landscape",
"icons": [{
"src": "/public/img/icon.png",
"sizes": "192x192",

19
sw.js Normal file
View file

@ -0,0 +1,19 @@
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.0.0/workbox-sw.js')
workbox.routing.registerRoute(
new RegExp('.*\.js'),
new workbox.strategies.NetworkFirst()
)
workbox.routing.registerRoute(
/\.(?:png|jpg|jpeg|svg|gif|eot|ttf|woff2?|otf)$/,
new workbox.strategies.CacheFirst({
cacheName: 'image-font-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 20,
maxAgeSeconds: 7 * 24 * 60 * 60
})
]
})
)