feat: implement service-worker

This commit is contained in:
Ayo Ayco 2024-08-15 18:47:19 +02:00
parent 6fede8ae6e
commit 0ff0f657e7
6 changed files with 374 additions and 6539 deletions

View file

@ -1,9 +1,16 @@
import { defineConfig } from 'astro/config';
import serviceWorker from '@ayco/astro-sw';
import sitemap from "@astrojs/sitemap";
// https://astro.build/config
export default defineConfig({
site: 'https://ayo.ayco.io',
integrations: [sitemap()]
integrations: [
sitemap(),
serviceWorker({
path: './src/sw.js',
assetCachePrefix: 'ayco-personal-site',
})
]
});

6427
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -12,11 +12,12 @@
"deploy": "astro build && scp -r dist ayo@ayco.io:~/ayco.io-flask/",
"copy:dist": "astro build && cp -R dist ../ayco.io-flask/"
},
"dependencies": {
"devDependencies": {
"@astro-reactive/form": "^0.10.0",
"@astro-reactive/validator": "^0.5.0",
"@astrojs/sitemap": "^3.1.2",
"astro": "^4.0.3",
"@astrojs/sitemap": "^3.1.6",
"@ayco/astro-sw": "^0.3.0",
"astro": "^4.14.1",
"astro-github-stats": "^0.7.0",
"astro-iconify": "^1.2.0"
}

View file

@ -7,22 +7,25 @@ settings:
importers:
.:
dependencies:
devDependencies:
'@astro-reactive/form':
specifier: ^0.10.0
version: 0.10.0(@types/node@22.1.0)(astro@4.13.2(@types/node@22.1.0))
version: 0.10.0(@types/node@22.3.0)(astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4))(rollup@4.20.0)(typescript@5.5.4)
'@astro-reactive/validator':
specifier: ^0.5.0
version: 0.5.0(@types/node@22.1.0)(astro@4.13.2(@types/node@22.1.0))
version: 0.5.0(@types/node@22.3.0)(astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4))(rollup@4.20.0)(typescript@5.5.4)
'@astrojs/sitemap':
specifier: ^3.1.2
specifier: ^3.1.6
version: 3.1.6
'@ayco/astro-sw':
specifier: ^0.3.0
version: 0.3.0
astro:
specifier: ^4.0.3
version: 4.13.2(@types/node@22.1.0)
specifier: ^4.14.1
version: 4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)
astro-github-stats:
specifier: ^0.7.0
version: 0.7.0(astro@4.13.2(@types/node@22.1.0))
version: 0.7.0(astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4))
astro-iconify:
specifier: ^1.2.0
version: 1.2.0
@ -52,8 +55,8 @@ packages:
peerDependencies:
astro: ^4.0.3
'@astrojs/compiler@2.10.2':
resolution: {integrity: sha512-bvH+v8AirwpRWCkYJEyWYdc5Cs/BjG2ZTxIJzttHilXgfKJAdW2496KsUQKzf5j2tOHtaHXKKn9hb9WZiBGpEg==}
'@astrojs/compiler@2.10.3':
resolution: {integrity: sha512-bL/O7YBxsFt55YHU021oL+xz+B/9HvGNId3F9xURN16aeqDK9juHGktdkCSXz+U4nqFACq6ZFvWomOzhV+zfPw==}
'@astrojs/internal-helpers@0.4.1':
resolution: {integrity: sha512-bMf9jFihO8YP940uD70SI/RDzIhUHJAolWVcO1v5PUivxGKvfLZTLTVVxEYzGYyPsA3ivdLNqMnL5VgmQySa+g==}
@ -72,6 +75,10 @@ packages:
resolution: {integrity: sha512-/ca/+D8MIKEC8/A9cSaPUqQNZm+Es/ZinRv0ZAzvu2ios7POQSsVD+VOj7/hypWNsNM3T7RpfgNq7H2TU1KEHA==}
engines: {node: ^18.17.1 || ^20.3.0 || >=21.0.0}
'@ayco/astro-sw@0.3.0':
resolution: {integrity: sha512-qlq0GaWPBiVNqhPohW9KrEdGC0U+73W9dgtRnNI6UcEloMFqk/W3S/KI6HeIvo1Mps5SUKI93T3Cbqo4GxmSow==}
engines: {node: '>=18.0.0'}
'@babel/code-frame@7.24.7':
resolution: {integrity: sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==}
engines: {node: '>=6.9.0'}
@ -304,8 +311,8 @@ packages:
cpu: [x64]
os: [win32]
'@iconify/tools@4.0.4':
resolution: {integrity: sha512-hX1Z3i1Tm6JxyrDv45jNEijPpepZZfal/4leFGtUC04H9LsgRo597BOBFB9PUZsQdFGLOxVUUfv6lqU/dC+xXw==}
'@iconify/tools@4.0.5':
resolution: {integrity: sha512-l8KoA1lxlN/FFjlMd3vjfD7BtcX/QnFWtlBapILMlJSBgM5zhDYak/ldw/LkKG3258q/0YmXa48sO/QpxX7ptg==}
'@iconify/types@2.0.0':
resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==}
@ -456,6 +463,18 @@ packages:
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
engines: {node: '>= 8'}
'@oslojs/encoding@0.4.1':
resolution: {integrity: sha512-hkjo6MuIK/kQR5CrGNdAPZhS01ZCXuWDRJ187zh6qqF2+yMHZpD9fAYpX8q2bOO6Ryhl3XpCT6kUX76N8hhm4Q==}
'@rollup/pluginutils@5.1.0':
resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
'@rollup/rollup-android-arm-eabi@4.20.0':
resolution: {integrity: sha512-TSpWzflCc4VGAUJZlPpgAJE1+V60MePDQnBd7PPkpuEmOy8i87aL6tinFGKBFKuEDikYpig72QzdT3QPYIi+oA==}
cpu: [arm]
@ -536,8 +555,8 @@ packages:
cpu: [x64]
os: [win32]
'@shikijs/core@1.12.1':
resolution: {integrity: sha512-biCz/mnkMktImI6hMfMX3H9kOeqsInxWEyCHbSlL8C/2TR1FqfmGxTLRNwYCKsyCyxWLbB8rEqXRVZuyxuLFmA==}
'@shikijs/core@1.13.0':
resolution: {integrity: sha512-Mj5NVfbAXcD1GnwOTSPl8hBn/T8UDpfFQTptp+p41n/CbUcJtOq98WaRD7Lz3hCglYotUTHUWtzu3JhK6XlkAA==}
'@trysound/sax@0.2.0':
resolution: {integrity: sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==}
@ -579,8 +598,8 @@ packages:
'@types/node@17.0.45':
resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==}
'@types/node@22.1.0':
resolution: {integrity: sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==}
'@types/node@22.3.0':
resolution: {integrity: sha512-nrWpWVaDZuaVc5X84xJ0vNrLvomM205oQyLsRt7OHNZbSHslcWsvgFR7O7hire2ZonjLrWBbedmotmIlJDVd6g==}
'@types/sax@1.2.7':
resolution: {integrity: sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==}
@ -588,8 +607,8 @@ packages:
'@types/tar@6.1.13':
resolution: {integrity: sha512-IznnlmU5f4WcGTh2ltRu/Ijpmk8wiWXfF0VA4s+HPjHZgvFggk1YaIkbo5krX/zUCzWF8N/l4+W/LNxnvAJ8nw==}
'@types/unist@3.0.2':
resolution: {integrity: sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==}
'@types/unist@3.0.3':
resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==}
'@types/yauzl@2.10.3':
resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==}
@ -644,16 +663,16 @@ packages:
astro-iconify@1.2.0:
resolution: {integrity: sha512-arLDiSop3DAHHS30raZysspkz5MO9moJJZ4rJk1Ty+4W1jZDa00Jme0LrnRJRDB6BB2EDTxC553fo20yz3MeYw==}
astro@4.13.2:
resolution: {integrity: sha512-bdfUV6zfOWOV/IbROqVx+1cuAFXY0PZpVxr4JO9YxCKa5AfQRR8RKXJ2k8QUjalA6dmxQ9FgAQw3FRrzHVOGEQ==}
astro@4.14.1:
resolution: {integrity: sha512-tLhGE+vHl+n66KgzyV7ek6ro2dqKenHqdxPb/R6x9ci+fKG5lSSOeb/dP/XVhpKUMcuV98IGWTxL5VPzqPFUJQ==}
engines: {node: ^18.17.1 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0'}
hasBin: true
asynckit@0.4.0:
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
axios@1.7.3:
resolution: {integrity: sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==}
axios@1.7.4:
resolution: {integrity: sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==}
axobject-query@4.1.0:
resolution: {integrity: sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ==}
@ -714,9 +733,9 @@ packages:
cheerio-select@2.1.0:
resolution: {integrity: sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==}
cheerio@1.0.0-rc.12:
resolution: {integrity: sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==}
engines: {node: '>= 6'}
cheerio@1.0.0:
resolution: {integrity: sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==}
engines: {node: '>=18.17'}
chownr@2.0.0:
resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==}
@ -879,8 +898,8 @@ packages:
eastasianwidth@0.2.0:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
electron-to-chromium@1.5.5:
resolution: {integrity: sha512-QR7/A7ZkMS8tZuoftC/jfqNkZLQO779SSW3YuZHP4eXpj3EffGLFcB/Xu9AAZQzLccTiCV+EmUo3ha4mQ9wnlA==}
electron-to-chromium@1.5.8:
resolution: {integrity: sha512-4Nx0gP2tPNBLTrFxBMHpkQbtn2hidPVr/+/FTtcCiBYTucqc70zRyVZiOLj17Ui3wTO7SQ1/N+hkHYzJjBzt6A==}
emoji-regex@10.3.0:
resolution: {integrity: sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==}
@ -891,6 +910,9 @@ packages:
emoji-regex@9.2.2:
resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==}
encoding-sniffer@0.2.0:
resolution: {integrity: sha512-ju7Wq1kg04I3HtiYIOrUrdfdDvkyO9s5XM8QAj/bN61Yo/Vb4vgJxy5vi4Yxk01gWHbrofpPtpxM8bKger9jhg==}
end-of-stream@1.4.4:
resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==}
@ -923,6 +945,9 @@ packages:
engines: {node: '>=4'}
hasBin: true
estree-walker@2.0.2:
resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==}
estree-walker@3.0.3:
resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==}
@ -1090,8 +1115,8 @@ packages:
html-void-elements@3.0.0:
resolution: {integrity: sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==}
htmlparser2@8.0.2:
resolution: {integrity: sha512-GYdjWKDkbRLkZ5geuHs5NY1puJ+PXwP7+fHPRz06Eirsb9ugf6d8kkXav6ADhcODhFFPMIXyxkxSuMf3D6NCFA==}
htmlparser2@9.1.0:
resolution: {integrity: sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==}
http-cache-semantics@4.1.1:
resolution: {integrity: sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==}
@ -1104,6 +1129,10 @@ packages:
resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==}
engines: {node: '>=16.17.0'}
iconv-lite@0.6.3:
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
engines: {node: '>=0.10.0'}
import-meta-resolve@4.1.0:
resolution: {integrity: sha512-I6fiaX09Xivtk+THaMfAwnA3MVA5Big1WHF1Dfx9hFuvNIWpXnorlkzhcQf6ehrqQiiZECRt1poOAkPmer3ruw==}
@ -1431,6 +1460,10 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
neotraverse@0.6.18:
resolution: {integrity: sha512-Z4SmBUweYa09+o6pG+eASabEpP6QkQ70yHj351pQoEXIs8uHbaU2DWVmzBANKgflPa47A50PtB2+NgRpQvr7vA==}
engines: {node: '>= 10'}
nlcst-to-string@4.0.0:
resolution: {integrity: sha512-YKLBCcUYKAg0FNlOBT6aI91qFmSiFKiluk655WzPF+DDMA02qIyy8uiRqI8QXtcFpEvll12LpL5MXqEmAZ+dcA==}
@ -1509,6 +1542,9 @@ packages:
parse5-htmlparser2-tree-adapter@7.0.0:
resolution: {integrity: sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==}
parse5-parser-stream@7.1.2:
resolution: {integrity: sha512-JyeQc9iwFLn5TbvvqACIF/VXG6abODeB3Fwmv/TGdLk2LfbWkaySGY72at4+Ty7EkPZj854u4CrICqNk2qIbow==}
parse5@7.1.2:
resolution: {integrity: sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==}
@ -1643,6 +1679,9 @@ packages:
run-parallel@1.2.0:
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
safer-buffer@2.1.2:
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
sax@1.4.1:
resolution: {integrity: sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==}
@ -1671,8 +1710,8 @@ packages:
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
engines: {node: '>=8'}
shiki@1.12.1:
resolution: {integrity: sha512-nwmjbHKnOYYAe1aaQyEBHvQymJgfm86ZSS7fT8OaPRr4sbAcBNz7PbfAikMEFSDQ6se2j2zobkXvVKcBOm0ysg==}
shiki@1.13.0:
resolution: {integrity: sha512-e0dWfnONbEv6xl7FJy3XIhsVHQ/65XHDZl92+6H9+4xWjfdo7pmkqG7Kg47KWtDiEtzM5Z+oEfb4vtRvoZ/X9w==}
short-unique-id@4.4.4:
resolution: {integrity: sha512-oLF1NCmtbiTWl2SqdXZQbo5KM1b7axdp0RgQLq8qCBBLoq+o3A5wmLrNM6bZIh54/a8BJ3l69kTXuxwZ+XCYuw==}
@ -1796,11 +1835,20 @@ packages:
resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==}
engines: {node: '>=12.20'}
typescript@5.5.4:
resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==}
engines: {node: '>=14.17'}
hasBin: true
ufo@1.5.4:
resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==}
undici-types@6.13.0:
resolution: {integrity: sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==}
undici-types@6.18.2:
resolution: {integrity: sha512-5ruQbENj95yDYJNS3TvcaxPMshV7aizdv/hWYjGIKoANWKjhWNBsr2YEuYZKodQulB1b8l7ILOuDQep3afowQQ==}
undici@6.19.7:
resolution: {integrity: sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A==}
engines: {node: '>=18.17'}
unified@11.0.5:
resolution: {integrity: sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA==}
@ -1847,8 +1895,8 @@ packages:
vfile@6.0.2:
resolution: {integrity: sha512-zND7NlS8rJYb/sPqkb13ZvbbUoExdbi4w3SfRrMq6R3FvnLQmmfpajJNITuuYm6AZ5uao9vy4BAos3EXBPf2rg==}
vite@5.4.0:
resolution: {integrity: sha512-5xokfMX0PIiwCMCMb9ZJcMyh5wbBun0zUzKib+L65vAZ8GY9ePZMXxFrHbr/Kyll2+LSCY7xtERPpxkBDKngwg==}
vite@5.4.1:
resolution: {integrity: sha512-1oE6yuNXssjrZdblI9AfBbHCC41nnyoVoEZxQnID6yvQZAFBzxxkqoFLtHUMkYunL8hwOLEjgTuxpkRxvba3kA==}
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
peerDependencies:
@ -1893,6 +1941,14 @@ packages:
resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==}
engines: {node: '>= 8'}
whatwg-encoding@3.1.1:
resolution: {integrity: sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==}
engines: {node: '>=18'}
whatwg-mimetype@4.0.0:
resolution: {integrity: sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==}
engines: {node: '>=18'}
which-pm-runs@1.1.0:
resolution: {integrity: sha512-n1brCuqClxfFfq/Rb0ICg9giSZqCS+pLtccdag6C2HyufBrh3fBOiy9nb6ggRMvWOVH5GrdJskj5iGTZNxd7SA==}
engines: {node: '>=4'}
@ -1917,16 +1973,15 @@ packages:
wrappy@1.0.2:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
xxhash-wasm@1.0.2:
resolution: {integrity: sha512-ibF0Or+FivM9lNrg+HGJfVX8WJqgo+kCLDc4vx6xMeTce7Aj+DLttKbxxRR/gNLSAelRc1omAPlJ77N/Jem07A==}
yallist@3.1.1:
resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==}
yallist@4.0.0:
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
yargs-parser@21.1.1:
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
engines: {node: '>=12'}
yauzl@2.10.0:
resolution: {integrity: sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==}
@ -1943,6 +1998,12 @@ packages:
peerDependencies:
zod: ^3.23.3
zod-to-ts@1.2.0:
resolution: {integrity: sha512-x30XE43V+InwGpvTySRNz9kB7qFU8DlyEy7BsSTCHPH1R0QasMmHWZDCzYm6bVXtj/9NNJAZF3jW8rzFvH5OFA==}
peerDependencies:
typescript: ^4.9.4 || ^5.0.2
zod: ^3
zod@3.23.8:
resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==}
@ -1963,13 +2024,14 @@ snapshots:
'@antfu/utils@0.7.10': {}
'@astro-reactive/common@0.3.0(@types/node@22.1.0)':
'@astro-reactive/common@0.3.0(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)':
dependencies:
astro: 4.13.2(@types/node@22.1.0)
astro: 4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)
transitivePeerDependencies:
- '@types/node'
- less
- lightningcss
- rollup
- sass
- sass-embedded
- stylus
@ -1978,16 +2040,17 @@ snapshots:
- terser
- typescript
'@astro-reactive/form@0.10.0(@types/node@22.1.0)(astro@4.13.2(@types/node@22.1.0))':
'@astro-reactive/form@0.10.0(@types/node@22.3.0)(astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4))(rollup@4.20.0)(typescript@5.5.4)':
dependencies:
'@astro-reactive/common': 0.3.0(@types/node@22.1.0)
'@astro-reactive/validator': 0.5.0(@types/node@22.1.0)(astro@4.13.2(@types/node@22.1.0))
astro: 4.13.2(@types/node@22.1.0)
'@astro-reactive/common': 0.3.0(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)
'@astro-reactive/validator': 0.5.0(@types/node@22.3.0)(astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4))(rollup@4.20.0)(typescript@5.5.4)
astro: 4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)
short-unique-id: 4.4.4
transitivePeerDependencies:
- '@types/node'
- less
- lightningcss
- rollup
- sass
- sass-embedded
- stylus
@ -1996,14 +2059,15 @@ snapshots:
- terser
- typescript
'@astro-reactive/validator@0.5.0(@types/node@22.1.0)(astro@4.13.2(@types/node@22.1.0))':
'@astro-reactive/validator@0.5.0(@types/node@22.3.0)(astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4))(rollup@4.20.0)(typescript@5.5.4)':
dependencies:
'@astro-reactive/common': 0.3.0(@types/node@22.1.0)
astro: 4.13.2(@types/node@22.1.0)
'@astro-reactive/common': 0.3.0(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)
astro: 4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)
transitivePeerDependencies:
- '@types/node'
- less
- lightningcss
- rollup
- sass
- sass-embedded
- stylus
@ -2012,7 +2076,7 @@ snapshots:
- terser
- typescript
'@astrojs/compiler@2.10.2': {}
'@astrojs/compiler@2.10.3': {}
'@astrojs/internal-helpers@0.4.1': {}
@ -2030,7 +2094,7 @@ snapshots:
remark-parse: 11.0.0
remark-rehype: 11.1.0
remark-smartypants: 3.0.2
shiki: 1.12.1
shiki: 1.13.0
unified: 11.0.5
unist-util-remove-position: 5.0.0
unist-util-visit: 5.0.0
@ -2061,6 +2125,8 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@ayco/astro-sw@0.3.0': {}
'@babel/code-frame@7.24.7':
dependencies:
'@babel/highlight': 7.24.7
@ -2269,13 +2335,14 @@ snapshots:
'@esbuild/win32-x64@0.21.5':
optional: true
'@iconify/tools@4.0.4':
'@iconify/tools@4.0.5':
dependencies:
'@iconify/types': 2.0.0
'@iconify/utils': 2.1.30
'@types/tar': 6.1.13
axios: 1.7.3
cheerio: 1.0.0-rc.12
axios: 1.7.4
cheerio: 1.0.0
domhandler: 5.0.3
extract-zip: 2.0.1
local-pkg: 0.5.0
pathe: 1.1.2
@ -2403,6 +2470,16 @@ snapshots:
'@nodelib/fs.scandir': 2.1.5
fastq: 1.17.1
'@oslojs/encoding@0.4.1': {}
'@rollup/pluginutils@5.1.0(rollup@4.20.0)':
dependencies:
'@types/estree': 1.0.5
estree-walker: 2.0.2
picomatch: 2.3.1
optionalDependencies:
rollup: 4.20.0
'@rollup/rollup-android-arm-eabi@4.20.0':
optional: true
@ -2451,7 +2528,7 @@ snapshots:
'@rollup/rollup-win32-x64-msvc@4.20.0':
optional: true
'@shikijs/core@1.12.1':
'@shikijs/core@1.13.0':
dependencies:
'@types/hast': 3.0.4
@ -2488,23 +2565,23 @@ snapshots:
'@types/hast@3.0.4':
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
'@types/mdast@4.0.4':
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
'@types/ms@0.7.34': {}
'@types/nlcst@2.0.3':
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
'@types/node@17.0.45': {}
'@types/node@22.1.0':
'@types/node@22.3.0':
dependencies:
undici-types: 6.13.0
undici-types: 6.18.2
'@types/sax@1.2.7':
dependencies:
@ -2512,14 +2589,14 @@ snapshots:
'@types/tar@6.1.13':
dependencies:
'@types/node': 22.1.0
'@types/node': 22.3.0
minipass: 4.2.8
'@types/unist@3.0.2': {}
'@types/unist@3.0.3': {}
'@types/yauzl@2.10.3':
dependencies:
'@types/node': 22.1.0
'@types/node': 22.3.0
optional: true
'@ungap/structured-clone@1.2.0': {}
@ -2554,13 +2631,13 @@ snapshots:
array-iterate@2.0.1: {}
astro-github-stats@0.7.0(astro@4.13.2(@types/node@22.1.0)):
astro-github-stats@0.7.0(astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)):
dependencies:
astro: 4.13.2(@types/node@22.1.0)
astro: 4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4)
astro-iconify@1.2.0:
dependencies:
'@iconify/tools': 4.0.4
'@iconify/tools': 4.0.5
node-fetch: 3.3.2
resolve-pkg: 2.0.0
svgo: 3.3.2
@ -2568,9 +2645,9 @@ snapshots:
- debug
- supports-color
astro@4.13.2(@types/node@22.1.0):
astro@4.14.1(@types/node@22.3.0)(rollup@4.20.0)(typescript@5.5.4):
dependencies:
'@astrojs/compiler': 2.10.2
'@astrojs/compiler': 2.10.3
'@astrojs/internal-helpers': 0.4.1
'@astrojs/markdown-remark': 5.2.0
'@astrojs/telemetry': 3.1.0
@ -2580,6 +2657,8 @@ snapshots:
'@babel/plugin-transform-react-jsx': 7.25.2(@babel/core@7.25.2)
'@babel/traverse': 7.25.3
'@babel/types': 7.25.2
'@oslojs/encoding': 0.4.1
'@rollup/pluginutils': 5.1.0(rollup@4.20.0)
'@types/babel__core': 7.20.5
'@types/cookie': 0.6.0
acorn: 8.12.1
@ -2610,7 +2689,9 @@ snapshots:
js-yaml: 4.1.0
kleur: 4.1.5
magic-string: 0.30.11
micromatch: 4.0.7
mrmime: 2.0.0
neotraverse: 0.6.18
ora: 8.0.1
p-limit: 6.1.0
p-queue: 8.0.1
@ -2619,24 +2700,26 @@ snapshots:
prompts: 2.4.2
rehype: 13.0.1
semver: 7.6.3
shiki: 1.12.1
shiki: 1.13.0
string-width: 7.2.0
strip-ansi: 7.1.0
tsconfck: 3.1.1
tsconfck: 3.1.1(typescript@5.5.4)
unist-util-visit: 5.0.0
vfile: 6.0.2
vite: 5.4.0(@types/node@22.1.0)
vitefu: 0.2.5(vite@5.4.0(@types/node@22.1.0))
vite: 5.4.1(@types/node@22.3.0)
vitefu: 0.2.5(vite@5.4.1(@types/node@22.3.0))
which-pm: 3.0.0
yargs-parser: 21.1.1
xxhash-wasm: 1.0.2
zod: 3.23.8
zod-to-json-schema: 3.23.2(zod@3.23.8)
zod-to-ts: 1.2.0(typescript@5.5.4)(zod@3.23.8)
optionalDependencies:
sharp: 0.33.4
transitivePeerDependencies:
- '@types/node'
- less
- lightningcss
- rollup
- sass
- sass-embedded
- stylus
@ -2647,7 +2730,7 @@ snapshots:
asynckit@0.4.0: {}
axios@1.7.3:
axios@1.7.4:
dependencies:
follow-redirects: 1.15.6
form-data: 4.0.0
@ -2681,7 +2764,7 @@ snapshots:
browserslist@4.23.3:
dependencies:
caniuse-lite: 1.0.30001651
electron-to-chromium: 1.5.5
electron-to-chromium: 1.5.8
node-releases: 2.0.18
update-browserslist-db: 1.1.0(browserslist@4.23.3)
@ -2716,15 +2799,19 @@ snapshots:
domhandler: 5.0.3
domutils: 3.1.0
cheerio@1.0.0-rc.12:
cheerio@1.0.0:
dependencies:
cheerio-select: 2.1.0
dom-serializer: 2.0.0
domhandler: 5.0.3
domutils: 3.1.0
htmlparser2: 8.0.2
encoding-sniffer: 0.2.0
htmlparser2: 9.1.0
parse5: 7.1.2
parse5-htmlparser2-tree-adapter: 7.0.0
parse5-parser-stream: 7.1.2
undici: 6.19.7
whatwg-mimetype: 4.0.0
chownr@2.0.0: {}
@ -2867,7 +2954,7 @@ snapshots:
eastasianwidth@0.2.0: {}
electron-to-chromium@1.5.5: {}
electron-to-chromium@1.5.8: {}
emoji-regex@10.3.0: {}
@ -2875,6 +2962,11 @@ snapshots:
emoji-regex@9.2.2: {}
encoding-sniffer@0.2.0:
dependencies:
iconv-lite: 0.6.3
whatwg-encoding: 3.1.1
end-of-stream@1.4.4:
dependencies:
once: 1.4.0
@ -2917,6 +3009,8 @@ snapshots:
esprima@4.0.1: {}
estree-walker@2.0.2: {}
estree-walker@3.0.3:
dependencies:
'@types/estree': 1.0.5
@ -3069,7 +3163,7 @@ snapshots:
hast-util-from-parse5@8.0.1:
dependencies:
'@types/hast': 3.0.4
'@types/unist': 3.0.2
'@types/unist': 3.0.3
devlop: 1.1.0
hastscript: 8.0.0
property-information: 6.5.0
@ -3088,7 +3182,7 @@ snapshots:
hast-util-raw@9.0.4:
dependencies:
'@types/hast': 3.0.4
'@types/unist': 3.0.2
'@types/unist': 3.0.3
'@ungap/structured-clone': 1.2.0
hast-util-from-parse5: 8.0.1
hast-util-to-parse5: 8.0.0
@ -3104,7 +3198,7 @@ snapshots:
hast-util-to-html@9.0.1:
dependencies:
'@types/hast': 3.0.4
'@types/unist': 3.0.2
'@types/unist': 3.0.3
ccount: 2.0.1
comma-separated-tokens: 2.0.3
hast-util-raw: 9.0.4
@ -3129,7 +3223,7 @@ snapshots:
hast-util-to-text@4.0.2:
dependencies:
'@types/hast': 3.0.4
'@types/unist': 3.0.2
'@types/unist': 3.0.3
hast-util-is-element: 3.0.0
unist-util-find-after: 5.0.0
@ -3149,7 +3243,7 @@ snapshots:
html-void-elements@3.0.0: {}
htmlparser2@8.0.2:
htmlparser2@9.1.0:
dependencies:
domelementtype: 2.3.0
domhandler: 5.0.3
@ -3162,6 +3256,10 @@ snapshots:
human-signals@5.0.0: {}
iconv-lite@0.6.3:
dependencies:
safer-buffer: 2.1.2
import-meta-resolve@4.1.0: {}
is-arrayish@0.3.2:
@ -3266,7 +3364,7 @@ snapshots:
mdast-util-definitions@6.0.0:
dependencies:
'@types/mdast': 4.0.4
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-visit: 5.0.0
mdast-util-find-and-replace@3.0.1:
@ -3279,7 +3377,7 @@ snapshots:
mdast-util-from-markdown@2.0.1:
dependencies:
'@types/mdast': 4.0.4
'@types/unist': 3.0.2
'@types/unist': 3.0.3
decode-named-character-reference: 1.0.2
devlop: 1.1.0
mdast-util-to-string: 4.0.0
@ -3370,7 +3468,7 @@ snapshots:
mdast-util-to-markdown@2.1.0:
dependencies:
'@types/mdast': 4.0.4
'@types/unist': 3.0.2
'@types/unist': 3.0.3
longest-streak: 3.1.0
mdast-util-phrasing: 4.1.0
mdast-util-to-string: 4.0.0
@ -3624,6 +3722,8 @@ snapshots:
nanoid@3.3.7: {}
neotraverse@0.6.18: {}
nlcst-to-string@4.0.0:
dependencies:
'@types/nlcst': 2.0.3
@ -3706,7 +3806,7 @@ snapshots:
parse-latin@7.0.0:
dependencies:
'@types/nlcst': 2.0.3
'@types/unist': 3.0.2
'@types/unist': 3.0.3
nlcst-to-string: 4.0.0
unist-util-modify-children: 4.0.0
unist-util-visit-children: 3.0.0
@ -3717,6 +3817,10 @@ snapshots:
domhandler: 5.0.3
parse5: 7.1.2
parse5-parser-stream@7.1.2:
dependencies:
parse5: 7.1.2
parse5@7.1.2:
dependencies:
entities: 4.5.0
@ -3909,6 +4013,8 @@ snapshots:
dependencies:
queue-microtask: 1.2.3
safer-buffer@2.1.2: {}
sax@1.4.1: {}
section-matter@1.0.0:
@ -3953,9 +4059,9 @@ snapshots:
shebang-regex@3.0.0: {}
shiki@1.12.1:
shiki@1.13.0:
dependencies:
'@shikijs/core': 1.12.1
'@shikijs/core': 1.13.0
'@types/hast': 3.0.4
short-unique-id@4.4.4: {}
@ -4060,20 +4166,26 @@ snapshots:
trough@2.2.0: {}
tsconfck@3.1.1: {}
tsconfck@3.1.1(typescript@5.5.4):
optionalDependencies:
typescript: 5.5.4
tslib@2.6.3:
optional: true
type-fest@2.19.0: {}
typescript@5.5.4: {}
ufo@1.5.4: {}
undici-types@6.13.0: {}
undici-types@6.18.2: {}
undici@6.19.7: {}
unified@11.0.5:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
bail: 2.0.2
devlop: 1.1.0
extend: 3.0.2
@ -4083,43 +4195,43 @@ snapshots:
unist-util-find-after@5.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-is: 6.0.0
unist-util-is@6.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-modify-children@4.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
array-iterate: 2.0.1
unist-util-position@5.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-remove-position@5.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-visit: 5.0.0
unist-util-stringify-position@4.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-visit-children@3.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-visit-parents@6.0.1:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-is: 6.0.0
unist-util-visit@5.0.0:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-is: 6.0.0
unist-util-visit-parents: 6.0.1
@ -4131,37 +4243,43 @@ snapshots:
vfile-location@5.0.3:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
vfile: 6.0.2
vfile-message@4.0.2:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-stringify-position: 4.0.0
vfile@6.0.2:
dependencies:
'@types/unist': 3.0.2
'@types/unist': 3.0.3
unist-util-stringify-position: 4.0.0
vfile-message: 4.0.2
vite@5.4.0(@types/node@22.1.0):
vite@5.4.1(@types/node@22.3.0):
dependencies:
esbuild: 0.21.5
postcss: 8.4.41
rollup: 4.20.0
optionalDependencies:
'@types/node': 22.1.0
'@types/node': 22.3.0
fsevents: 2.3.3
vitefu@0.2.5(vite@5.4.0(@types/node@22.1.0)):
vitefu@0.2.5(vite@5.4.1(@types/node@22.3.0)):
optionalDependencies:
vite: 5.4.0(@types/node@22.1.0)
vite: 5.4.1(@types/node@22.3.0)
web-namespaces@2.0.1: {}
web-streams-polyfill@3.3.3: {}
whatwg-encoding@3.1.1:
dependencies:
iconv-lite: 0.6.3
whatwg-mimetype@4.0.0: {}
which-pm-runs@1.1.0: {}
which-pm@3.0.0:
@ -4184,12 +4302,12 @@ snapshots:
wrappy@1.0.2: {}
xxhash-wasm@1.0.2: {}
yallist@3.1.1: {}
yallist@4.0.0: {}
yargs-parser@21.1.1: {}
yauzl@2.10.0:
dependencies:
buffer-crc32: 0.2.13
@ -4203,6 +4321,11 @@ snapshots:
dependencies:
zod: 3.23.8
zod-to-ts@1.2.0(typescript@5.5.4)(zod@3.23.8):
dependencies:
typescript: 5.5.4
zod: 3.23.8
zod@3.23.8: {}
zwitch@2.0.4: {}

1
src/env.d.ts vendored
View file

@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />

130
src/sw.js Normal file
View file

@ -0,0 +1,130 @@
/**
* Note: @ayco/astro-sw integration injects variables `__prefix`, `__version`, & `__assets`
* -- find usage in `astro.config.mjs` integrations
* @see https://ayco.io/n/@ayco/astro-sw
*/
const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}`
const addResourcesToCache = async (resources) => {
const cache = await caches.open(cacheName);
console.log('[cozy-sw]: adding resources to cache...', resources)
await cache.addAll(resources);
};
const putInCache = async (request, response) => {
const cache = await caches.open(cacheName);
console.log('[cozy-sw]: adding one response to cache...', request.url)
// if exists, replace
const keys = await cache.keys();
if(keys.includes(request)) {
cache.delete(request);
}
await cache.put(request, response);
};
const cacheAndRevalidate = async ({ request, preloadResponsePromise, fallbackUrl }) => {
const cache = await caches.open(cacheName);
// Try get the resource from the cache
const responseFromCache = await cache.match(request);
try {
// get network response for revalidation of stale assets
const responseFromNetwork = await fetch(request.clone());
if (responseFromNetwork) {
console.info('[cozy-sw]: fetched updated assets', responseFromNetwork.url);
putInCache(request, responseFromNetwork.clone());
}
if (responseFromCache) {
console.info('[cozy-sw]: using cached response', responseFromCache.url);
return responseFromCache;
} else{
console.info('[cozy-sw]: using network response', responseFromNetwork.url);
return responseFromNetwork;
}
} catch(error) {
console.info('[cozy-sw]: failed to fetch updated assets', request.url);
if (responseFromCache) {
console.info('[cozy-sw]: using cached response', responseFromCache.url);
return responseFromCache;
}
}
// Try to use the preloaded response, if it's there
// NOTE: Chrome throws errors regarding preloadResponse, see:
// https://bugs.chromium.org/p/chromium/issues/detail?id=1420515
// https://github.com/mdn/dom-examples/issues/145
// To avoid those errors, remove or comment out this block of preloadResponse
// code along with enableNavigationPreload() and the "activate" listener.
const preloadResponse = await preloadResponsePromise;
if (preloadResponse) {
putInCache(request, preloadResponse.clone());
console.info('[cozy-sw]: using preload response', preloadResponse.url);
return preloadResponse;
}
try {
// Try to get the resource from the network for 5 seconds
const responseFromNetwork = await fetch(request.clone(), {signal: AbortSignal.timeout(5000)});
// response may be used only once
// we need to save clone to put one copy in cache
// and serve second one
putInCache(request, responseFromNetwork.clone());
console.info('[cozy-sw]: using network response', responseFromNetwork.url);
return responseFromNetwork;
} catch (error) {
// Try the fallback
const fallbackResponse = await cache.match(fallbackUrl);
if (fallbackResponse) {
console.info('[cozy-sw]: using fallback cached response', fallbackResponse.url);
return fallbackResponse;
}
// when even the fallback response is not available,
// there is nothing we can do, but we must always
// return a Response object
return new Response('Network error happened', {
status: 408,
headers: { 'Content-Type': 'text/plain' },
});
}
};
const enableNavigationPreload = async () => {
if (self.registration.navigationPreload) {
// Enable navigation preloads!
await self.registration.navigationPreload.enable();
}
};
self.addEventListener('activate', (event) => {
console.log('[cozy-sw]: activating...', event)
event.waitUntil(enableNavigationPreload());
});
self.addEventListener('install', (event) => {
console.log('[cozy-sw]: installing...', event)
event.waitUntil(
addResourcesToCache([
...(__assets ?? [])
])
);
self.skipWaiting(); // activate updated SW
});
self.addEventListener('fetch', (event) => {
// ... else, use network first
event.respondWith(
cacheAndRevalidate({
request: event.request,
preloadResponsePromise: event.preloadResponse,
fallbackUrl: './',
})
);
});