- How do I add PWA functionality to a Laravel app using Blade templates?
- Use the two Blade directives `@PwaHead` in your `<head>` section and `@RegisterServiceWorkerScript` before your closing `</body>` tag. The package auto-generates the manifest and service worker files based on your `config/pwa.php` settings. No additional frontend code is needed for basic functionality.
- Does this package work with Laravel 13 and Livewire 3?
- Yes, the package supports Laravel 8 through 13 and includes basic Livewire compatibility via the `livewire-app` config option. However, dynamic manifest updates (e.g., via the facade) may require manual adjustments to avoid hydration conflicts in Livewire components.
- Can I customize the service worker beyond the default caching strategy?
- The package provides a default service worker template, but you can override it by publishing the assets (`php artisan vendor:publish --tag=pwa-assets`) and modifying the JavaScript file. For advanced strategies like Stale-While-Revalidate, you’ll need to manually edit the template or extend the package.
- Will this package work with Vite or Webpack asset pipelines?
- Yes, but you must exclude the generated `manifest.json` and service worker files from your bundler. Add them to `.viteignore` or `webpack.ignore.js` to prevent processing. The package writes these files to the `public/` directory, so ensure your pipeline respects static assets.
- How do I test the PWA install prompt in development without HTTPS?
- PWAs require HTTPS for production, but you can test locally using tools like `ngrok` to expose your Laravel app via HTTPS (e.g., `ngrok http 8000`). Alternatively, use Laravel Valet with HTTPS enabled or configure your browser to trust a self-signed certificate for testing.
- Does this package support push notifications or background sync?
- No, the package focuses on core PWA features: manifest generation, service worker registration, and install prompts. For push notifications or background sync, you’ll need to extend the service worker template manually or use additional packages like `laravel-push-notification-channel`.
- How do I update the PWA manifest dynamically (e.g., for multi-tenant apps)?
- Use the `Pwa` facade to modify the manifest at runtime, such as `Pwa::setName('Custom App Name')`. The package caches the manifest in memory and regenerates it on changes. For production, ensure your `public/` directory has writable permissions for the `manifest.json` file.
- Are there any alternatives to this package for Laravel PWAs?
- Yes, alternatives include `laravel-pwa` by Spatie (now deprecated) and `laravel-pwa-toolbox`, which offers more advanced features like offline page customization and analytics. However, `erag/laravel-pwa` is lighter, Laravel-native, and actively maintained for modern Laravel versions.
- How do I track PWA installs or offline usage in my app?
- The package doesn’t include built-in analytics, but you can monitor installs using the `beforeinstallprompt` event in JavaScript and log offline usage via `navigator.onLine` events. Integrate with tools like Google Analytics or Mixpanel by extending the service worker or adding custom JavaScript.
- What are the performance implications of using this package in production?
- The package adds minimal overhead: the service worker is registered once per session, and the manifest is cached by the browser. Ensure your `public/` directory is optimized for static asset delivery (e.g., using a CDN or Laravel’s built-in caching). Test offline performance with tools like Lighthouse to identify bottlenecks.