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

Conversation

knownotunknown
Copy link

@knownotunknown knownotunknown commented Oct 20, 2024

Features

  • Caches core assets for offline use
  • Shows offline page when network fails

Testing

  • Added Lighthouse PWA testing in CI
  • Requires perfect PWA score (1.0) to pass CI checks
  • Tests core PWA requirements including:
    • Service worker registration
    • Valid manifest
    • Required icons
    • Proper display settings

Potential Improvements

  • Can implement the Richer PWA UI which allows us to customize the PWA installation process

    Demo (Ctrl + r to reload PWA app)

https://www.loom.com/share/042bfb4cdda84da0b4775f44cfd4ff05?sid=7f6a27a2-5de4-4d17-bb9f-d7984d4d0bd2

Closes #59

Copy link

github-actions bot commented Oct 20, 2024

deployed preview: https://108.connect-d5y.pages.dev

Welcome to new-connect! Make sure to:

  • read the contributing guidelines
  • mark your PR as a draft until it's ready to review
  • post the preview on Discord; feedback from users will speedup the PR review

Mobile

Desktop

"ci": {
"collect": {
"url": ["http://localhost:4173"],
"startServerCommand": "bun run start | sed -u 's/^/[server] /' & pid=$!; sleep 2; echo 'Server is ready'; wait $pid",
Copy link
Author

Choose a reason for hiding this comment

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

Lighthouse CI uses "Server is ready" echo command to indicate when to start analysis.

@@ -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

@@ -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.

type: 'asset',
fileName: `pwa-assets/${file}`,
source: fs.readFileSync(path.resolve(pwaAssetsDir, file)),
})
Copy link
Author

@knownotunknown knownotunknown Nov 2, 2024

Choose a reason for hiding this comment

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

pwa-asset-generator doesn't allow us to specify a reference path for assets separate from where they're actually placed (ie: assets placed in dist are referenced as /dist/pwa-assets by pwa-asset-generator's auto-generated code)

So this manually places the assets where they need to be.

@knownotunknown knownotunknown marked this pull request as ready for review November 2, 2024 22:33
@adeebshihadeh
Copy link
Contributor

This PR is quite large. Anything we can split out?

@knownotunknown knownotunknown marked this pull request as draft November 4, 2024 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement PWA features
2 participants