Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zerosAndOnes's avatar

Laravel PWA Question

Hi all, I am working on a project where I'd eventually like users to be able to use the website like an app on their phone since I don't want to build a mobile app due to the processes involved with stores.

I am developed the backend part with laravel (API), and have been stuck on deciding what frontend framework to use (because I can make PWA on them)--I finally decided on Nuxt, but also stuck on how it will work on a host like hostinger (Shared). So I am now wondering if it is possible to build PWA on Laravel, if I decided to use Livewire + Laravel.

Thanks.

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly, you can build a Progressive Web App (PWA) using Laravel along with Livewire. PWAs are essentially web applications that use modern web capabilities to deliver an app-like experience to users, and they can be built with any web technology stack, including Laravel.

Here's a high-level overview of the steps you would take to make your Laravel + Livewire application a PWA:

  1. Create a Web App Manifest: This JSON file describes the basic metadata of your application (name, icons, start URL, display type, etc.) and is crucial for the 'Add to Home Screen' feature.
{
  "name": "Your App",
  "short_name": "App",
  "start_url": "/",
  "display": "standalone",
  "background_color": "#ffffff",
  "description": "An amazing PWA with Laravel and Livewire",
  "icons": [
    {
      "src": "path/to/icon.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "path/to/larger-icon.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ]
}
  1. Service Worker: Implement a service worker in JavaScript, which is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. This is where you'll handle things like caching for offline support.
self.addEventListener('install', event => {
  event.waitUntil(
    caches.open('v1').then(cache => {
      return cache.addAll([
        '/offline.html',
        '/css/app.css',
        '/js/app.js'
        // etc
      ]);
    })
  );
});

self.addEventListener('fetch', event => {
  event.respondWith(
    caches.match(event.request).then(response => {
      return response || fetch(event.request);
    }).catch(() => {
      return caches.match('/offline.html');
    })
  );
});
  1. Register the Service Worker: In your main JavaScript file or a specific script for the service worker, you need to register the service worker.
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/service-worker.js')
    .then(function(registration) {
      console.log('Service Worker Registered!', registration);
    })
    .catch(function(error) {
      console.log('Service Worker registration failed:', error);
    });
}
  1. HTTPS: Ensure your application is served over HTTPS, as service workers require a secure context to work.

  2. Testing: Test your PWA on different devices and browsers to ensure compatibility and performance.

  3. Deployment: When deploying on a shared host like Hostinger, you'll need to ensure that your service worker and manifest file are correctly served. You may need to configure your .htaccess file or server settings to properly serve these static files.

For Laravel and Livewire, you can use the laravel-mix to compile your assets and include the service worker and manifest file in your public directory. Livewire will work seamlessly with this setup as it's primarily a server-side rendering framework and doesn't interfere with the client-side aspects of a PWA.

Remember that building a PWA is not just about the technical setup; it's also about providing a seamless, app-like user experience, which includes responsive design, fast load times, and offline capabilities. Keep these in mind as you design and develop your application.

Please or to participate in this conversation.