Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pwa deployment in cloudflare #108

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bc4fc7d
feat: migrated js/html code for PWA feat. Not including assets/bundling
knownotunknown Oct 19, 2024
e1928fd
Revert "feat: migrated js/html code for PWA feat. Not including asset…
knownotunknown Oct 19, 2024
c423fb0
Reapply "feat: migrated js/html code for PWA feat. Not including asse…
knownotunknown Oct 19, 2024
8250907
Update register-service-worker.ts
knownotunknown Oct 19, 2024
a9fac0c
Update register-service-worker.ts
knownotunknown Oct 19, 2024
236d727
test: further narrowing down point of failure
knownotunknown Oct 19, 2024
1ea3a9b
Update service-worker.js
knownotunknown Oct 19, 2024
94a7244
feat: added caching
knownotunknown Oct 19, 2024
fea3b99
Update service-worker.js
knownotunknown Oct 19, 2024
d127624
Update service-worker.js
knownotunknown Oct 19, 2024
c6cf74c
feat: added assets
knownotunknown Oct 19, 2024
9029d25
feat: generated assets
knownotunknown Oct 19, 2024
44d98ba
Update bun.lockb
knownotunknown Oct 19, 2024
2521e6f
fix: properly referencing pwa assets path
knownotunknown Oct 19, 2024
f014d3d
fix: added bun.lockb
knownotunknown Oct 19, 2024
fc5f7a5
Update service-worker.js
knownotunknown Oct 20, 2024
8f57fb7
Update service-worker.js
knownotunknown Oct 20, 2024
ae9d7e4
Update preview.yaml
knownotunknown Oct 20, 2024
ff02d79
Revert "Update preview.yaml"
knownotunknown Oct 20, 2024
8632975
Update service-worker.js
knownotunknown Oct 20, 2024
8e9c564
Update service-worker.js
knownotunknown Oct 20, 2024
afc881d
test: checking for preview deployment errors
knownotunknown Oct 20, 2024
c0b1a5d
Update preview.yaml
knownotunknown Oct 20, 2024
772147c
Update preview.yaml
knownotunknown Oct 20, 2024
93ee4a7
Update service-worker.js
knownotunknown Oct 21, 2024
c5f122a
feat: should handle redirects better now
knownotunknown Oct 27, 2024
c83c694
Update build.yaml
knownotunknown Oct 29, 2024
c5c6899
Create lighthouserc.json
knownotunknown Oct 29, 2024
ce40f13
refactor: cleaned up cruft
knownotunknown Nov 1, 2024
e3382a8
style: added line breaks back
knownotunknown Nov 1, 2024
cdfe390
refactor: removing possibly extraneous code
knownotunknown Nov 2, 2024
7c36616
Update lighthouserc.json
knownotunknown Nov 2, 2024
9a87c35
Update vite.config.ts
knownotunknown Nov 2, 2024
33f07f6
Update vite.config.ts
knownotunknown Nov 2, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ jobs:
node src/ci/dependency_report.cjs dist/ | column -t -s ":"
- run: ./check-bundle-size.sh

- name: Build for Lighthouse
run: bun run build

- name: Run Lighthouse CI
uses: treosh/lighthouse-ci-action@v10
id: lighthouse
with:
configPath: './lighthouserc.json'
uploadArtifacts: true
temporaryPublicStorage: true

- name: Upload Lighthouse reports
uses: actions/upload-artifact@v4
with:
name: lighthouse-reports
path: ${{ steps.lighthouse.outputs.resultsPath }}

- name: Check Lighthouse CI status
if: steps.lighthouse.outputs.assertionResults != '[]'
run: |
echo "Lighthouse CI assertions failed. Check the report for details."
exit 1

build:
runs-on: ubuntu-latest
timeout-minutes: 1
Expand Down
Binary file modified bun.lockb
Binary file not shown.
12 changes: 9 additions & 3 deletions check-bundle-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd $DIR

gzip -r -9 dist
BUNDLE_SIZE=$(du -sk dist | cut -f1)
echo "Bundle size is $BUNDLE_SIZE K"

# Calculate bundle size excluding PWA assets
BUNDLE_SIZE=$(find dist -type f \
! -name "apple-splash-*" \
! -name "apple-icon-*" \
-print0 | xargs -0 du -ck | grep total$ | cut -f1)

echo "Bundle size (excluding specified assets) is $BUNDLE_SIZE K"

if [ $BUNDLE_SIZE -lt 200 ]; then
echo "Bundle sizer lower than expected, let's lower the limit!"
echo "Bundle size lower than expected, let's lower the limit!"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default [
languageOptions: { globals: globals.browser },
},
{
ignores: ['.github', '.husky', '.vscode', 'node_modules', 'dist'],
ignores: ['.github', '.husky', '.vscode', 'node_modules', 'dist', 'src/service-worker.js'],
},
js.configs.recommended,
...ts.configs.recommendedTypeChecked,
Expand Down
68 changes: 44 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,58 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="theme-color" content="#1B1B1F" />
<meta name="description" content="manage your openpilot experience" />
<title>connect</title>

<link rel="manifest" href="/manifest.json" />
<link
href="/images/favicon-16x16.png"
rel="icon"
type="image/png"
sizes="16x16"
/>
<link
href="/images/favicon-32x32.png"
rel="icon"
type="image/png"
sizes="32x32"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],400,0..1,0&display=block"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Inter:[email protected]&family=JetBrains+Mono:wght@400;500&display=swap"
/>
<link rel="manifest" href="/manifest.json">
<link href="/images/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16">
<link href="/images/favicon-32x32.png" rel="icon" type="image/png" sizes="32x32">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],400,0..1,0&amp;display=block">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:[email protected]&amp;family=JetBrains+Mono:wght@400;500&amp;display=swap">
<!-- DON'T CHANGE MANUALLY. The below are auto-generated PWA assets (scripts defined in package.json). -->
<meta name="mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" href="pwa-assets/apple-icon-180.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2048-2732.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2732-2048.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1668-2388.jpg" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2388-1668.jpg" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1536-2048.jpg" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2048-1536.jpg" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1488-2266.jpg" media="(device-width: 744px) and (device-height: 1133px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2266-1488.jpg" media="(device-width: 744px) and (device-height: 1133px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1640-2360.jpg" media="(device-width: 820px) and (device-height: 1180px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2360-1640.jpg" media="(device-width: 820px) and (device-height: 1180px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1668-2224.jpg" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2224-1668.jpg" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1620-2160.jpg" media="(device-width: 810px) and (device-height: 1080px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2160-1620.jpg" media="(device-width: 810px) and (device-height: 1080px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1290-2796.jpg" media="(device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2796-1290.jpg" media="(device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1179-2556.jpg" media="(device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2556-1179.jpg" media="(device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1284-2778.jpg" media="(device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2778-1284.jpg" media="(device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1170-2532.jpg" media="(device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2532-1170.jpg" media="(device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1125-2436.jpg" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2436-1125.jpg" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1242-2688.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2688-1242.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-828-1792.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1792-828.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1242-2208.jpg" media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-2208-1242.jpg" media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-750-1334.jpg" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1334-750.jpg" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-640-1136.jpg" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="pwa-assets/apple-splash-1136-640.jpg" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
</head>
<body data-theme="dark" class="overflow-x-hidden bg-background text-on-background">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<script src="/src/index.tsx" type="module"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions lighthouserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"ci": {
"collect": {
"url": ["http://localhost:4173"],
"startServerCommand": "bun run start 2>&1 | sed -u 's/^/[server] /' & pid=$!; echo \"Server listening on port 4173\"; echo 'Server is ready'; wait $pid",
"startServerReadyPattern": "Server is ready",
"numberOfRuns": 1,
"settings": {
"chromeFlags": "--no-sandbox"
}
},
"assert": {
"assertions": {
"categories:pwa": ["error", { "minScore": 1 }]
}
}
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"scripts": {
"build": "vite build",
"dev": "vite",
"generate-pwa-assets": "npx pwa-asset-generator ./public/images/icon-vector.svg ./pwa-assets -m ./public/manifest.json -i ./index.html --sizes \"72x72,96x96,128x128,144x144,152x152,192x192,384x384,512x512\" --quality 75 --background \"#ffffff\" --padding \"10%\" --platform android,ios --opaque false",
"move-pwa-assets": "rm -rf ./public/pwa-assets && mv ./pwa-assets ./public/",
"pwa-setup": "npm run generate-pwa-assets && npm run move-pwa-assets",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. "generate-pwa-assets":

    • Takes our vector icon from public/images/icon-vector.svg
    • Generates various sizes of icons required for PWA (72px to 512px)
    • Updates manifest.json and index.html with the new icons
    • Applies settings:
      • 75% image quality for optimization
      • White background
      • 10% padding around icons
      • Compatible with both Android and iOS
      • Transparent background allowed
  2. "move-pwa-assets":

    • Moves generated assets to the public directory
    • Cleans up old assets first to avoid duplicates
  3. "pwa-setup":

    • Runs both commands in sequence to generate and organize PWA assets

"serve": "vite prefix",
"start": "vite preview",
"lint": "eslint --cache --cache-location node_modules/.eslintcache",
"prepare": "husky",
"pre-commit": "bun lint",
Expand Down Expand Up @@ -78,6 +82,7 @@
"solid-js": "JS ui framework"
},
"dependencies": {
"@lhci/cli": "^0.14.0",
"@mapbox/polyline": "^1.2.1",
"@solid-primitives/state-machine": "^0.0.3",
"@solidjs/router": "^0.13.5",
Expand Down
31 changes: 17 additions & 14 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@
"name": "comma connect",
"icons": [
{
"src": "/images/icon-vector.svg",
"type": "image/svg+xml",
"sizes": "512x512"
"src": "pwa-assets/manifest-icon-192.maskable.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/images/icon-192.png",
"src": "pwa-assets/manifest-icon-192.maskable.png",
"sizes": "192x192",
"type": "image/png",
"sizes": "192x192"
"purpose": "maskable"
},
{
"src": "/images/icon-256.png",
"src": "pwa-assets/manifest-icon-512.maskable.png",
"sizes": "512x512",
"type": "image/png",
"sizes": "256x256"
"purpose": "any"
},
{
"src": "/images/icon-384.png",
"src": "pwa-assets/manifest-icon-512.maskable.png",
"sizes": "512x512",
"type": "image/png",
"sizes": "384x384"
"purpose": "maskable"
},
{
"src": "/images/icon-512.png",
"src": "/images/icon-256.png",
"type": "image/png",
"sizes": "512x512"
"sizes": "256x256"
},
{
"src": "/images/icon-maskable.png",
"sizes": "512x512",
"src": "/images/icon-384.png",
"type": "image/png",
"purpose": "maskable"
"sizes": "384x384"
}
],
"id": "/",
Expand Down
69 changes: 69 additions & 0 deletions public/no-connection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>No Connection</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: rgb(27 27 33);
color: #ffffff;
}
.container {
text-align: center;
padding: 3rem;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 16px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(10px);
max-width: 80%;
}
h1 {
font-size: 2.5rem;
margin-bottom: 0.5rem;
}
p {
font-size: 1.1rem;
margin-bottom: 2rem;
opacity: 0.8;
}
.logo {
width: 128px;
height: 128px;
margin-bottom: 2rem;
filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));
}
.retry-button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 8px;
transition: background-color 0.3s;
}
.retry-button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<img src="/images/icon-256.png" alt="comma connect logo" class="logo">
<h1>You're Offline</h1>
<p>It seems you've lost your internet connection. Don't worry, we'll be here when you're back online.</p>
<button class="retry-button" onclick="window.location.reload();">Try Again</button>
</div>
</body>
</html>
Binary file added public/pwa-assets/apple-icon-180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1125-2436.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1136-640.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1170-2532.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1179-2556.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1242-2208.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1242-2688.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1284-2778.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1290-2796.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1334-750.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1488-2266.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1536-2048.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1620-2160.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1640-2360.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1668-2224.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1668-2388.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-1792-828.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2048-1536.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2048-2732.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2160-1620.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2208-1242.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2224-1668.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2266-1488.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2360-1640.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2388-1668.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-assets/apple-splash-2436-1125.jpg
Binary file added public/pwa-assets/apple-splash-2532-1170.jpg
Binary file added public/pwa-assets/apple-splash-2556-1179.jpg
Binary file added public/pwa-assets/apple-splash-2688-1242.jpg
Binary file added public/pwa-assets/apple-splash-2732-2048.jpg
Binary file added public/pwa-assets/apple-splash-2778-1284.jpg
Binary file added public/pwa-assets/apple-splash-2796-1290.jpg
Binary file added public/pwa-assets/apple-splash-640-1136.jpg
Binary file added public/pwa-assets/apple-splash-750-1334.jpg
Binary file added public/pwa-assets/apple-splash-828-1792.jpg
Binary file added public/pwa-assets/manifest-icon-192.maskable.png
Binary file added public/pwa-assets/manifest-icon-512.maskable.png
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @refresh reload */
import './index.css'
import { registerServiceWorker } from './utils/register-service-worker'

import { render } from 'solid-js/web'
import App from './App'
Expand All @@ -13,3 +14,4 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
}

render(() => <App />, root!)
registerServiceWorker()
76 changes: 76 additions & 0 deletions src/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const SERVICE_WORKER_VERSION = 1;
const CACHE_NAME = `comma-connect-cache-v${SERVICE_WORKER_VERSION}`;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incrementing the version number forces browsers to update their cached service worker when you deploy changes - without it, users might keep running old versions.

const STATIC_ASSETS = [
'/index.html',
'/manifest.json',
'/no-connection.html',
'/images/icon-256.png',
];

const CACHEABLE_URL_PATTERNS = [
/\/images\/.*\.(png|jpg|svg)$/,
/\/fonts\.googleapis\.com\//,
/\/fonts\.gstatic\.com\//,
];

self.addEventListener('install', (installEvent) => {
installEvent.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll(STATIC_ASSETS);
})
);
});

self.addEventListener('fetch', (fetchEvent) => {
if (fetchEvent.request.method !== 'GET') {
return;
}

if (shouldCacheUrl(fetchEvent.request.url)) {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then((cachedResponse) => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(fetchEvent.request).then((networkResponse) => {
if (networkResponse.status === 200) {
const clonedResponse = networkResponse.clone();
caches.open(CACHE_NAME).then((cache) => {
cache.put(fetchEvent.request, clonedResponse);
});
}
return networkResponse;
});
}).catch(handleFetchError)
);
} else {
fetchEvent.respondWith(
fetch(fetchEvent.request).catch(handleFetchError)
);
}
});

async function handleFetchError(error) {
try {
const cachedResponse = await caches.match('/no-connection.html');
if (cachedResponse) {
const body = await cachedResponse.blob();
return new Response(body, {
status: 200,
headers: cachedResponse.headers
});
}
} catch (cacheError) {
console.error('Cache error:', cacheError);
return new Response('An error occurred.', {
status: 503,
headers: { 'Content-Type': 'text/html' }
});
}
}

function shouldCacheUrl(url) {
const urlPath = new URL(url).pathname;
return CACHEABLE_URL_PATTERNS.some((pattern) => pattern.test(urlPath));
}
Loading
Loading