pwa-helpers is a collection of small, focused helper methods and mixins designed to reduce boilerplate when building Progressive Web Apps. It offers utilities for common PWA features such as client-side routing, network connectivity detection, dynamic metadata updates for SEO and social sharing, and media query monitoring. The current stable version is 0.9.1, with recent updates including TypeScript support introduced in v0.9.0. This library is designed to be framework-agnostic, providing vanilla JavaScript functions that can integrate with any web application stack, differentiating itself by its minimalist approach rather than being a comprehensive framework.
npm install pwa-helpersVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic routing, dynamic metadata updates, and network connectivity detection using `pwa-helpers`. It includes both initial setup and simulated programmatic navigation, showing how to integrate these helpers into a client-side application structure, and handle network status changes.
Ensure your project uses `import` statements and is configured for ESM. If targeting Node.js, ensure `"type": "module"` is set in your `package.json` or use an appropriate bundler like Rollup or Webpack. For browser environments, use modern script tags with `type="module"` or a bundler.
After calling `window.history.pushState({}, '', '/new-route');`, explicitly invoke your `handleNavigation(window.location);` function (or whatever callback you passed to `installRouter`).Always provide all desired metadata fields, even if some are empty strings, if you want full control over the tags. To remove a tag, you might need to manually target and remove the corresponding meta element, as `pwa-helpers` doesn't provide a 'clear' mechanism for individual fields.
If encountering TypeScript-related build issues after upgrading, verify your `tsconfig.json` settings (e.g., `include`, `exclude`, `allowSyntheticDefaultImports`). Typically, modern TypeScript setups will consume these types without issues.
Ensure you are using named ES module imports: `import { installRouter } from 'pwa-helpers/router.js';`. Verify that your build setup correctly handles ES modules.Always include the `.js` file extension in your `import` paths for `pwa-helpers` modules, e.g., `import { installRouter } from 'pwa-helpers/router.js';`. This is crucial for browser-native ESM and some Node.js module resolvers.