📎 Webclip
From create-react-app to PWA
The post argues that PWAs offer a single web-based app experience across devices, with offline use, home screen access, splash screens, and notifications. It also says they can reduce the cost and complexity of building separate web, Android, and iOS apps, even though PWAs are more complicated than normal web apps.
Reading notes#
- Create React App already includes support for PWAs, so a TypeScript React app can be created with
npx create-react-app pwa-react-typescript --template typescript. - Turning the app into a PWA means changing
serviceWorker.unregister()toserviceWorker.register()inindex.tsx. - The service worker caches static assets, supports offline use, and uses a cache-first strategy for local assets and navigation requests.
create-react-appuses Workbox to handle caching and offline behavior with default strategies.- The post notes that this setup gives little room for custom configuration if the defaults are not enough.
- A PWA also needs installability, an app name, an icon, and a splash screen, all of which are already included in the default setup.
- The app name is changed in
index.htmlandmanifest.json, and the manifest defines metadata such as icons,start_url,display,theme_color, andbackground_color. - Custom icons can be added by placing files in
public, updatingmanifest.json, and changing the Apple touch icon link inindex.htmlfor older Apple devices. - The app is then split into pages with
react-router-dom, addingHomeandAboutcomponents and updating the test to look for the About link. - Code splitting is added with
React.lazyandSuspense, so routes load only when needed. - After code splitting, the build produces multiple chunk files instead of one growing main bundle.
- The final step is deploying the app on Netlify from GitHub, using the default deploy settings and HTTPS so the service worker can run.
- The author then checks the deployed app with Google Chrome Developer Tools audit, which gives a good result.
