Configure Progressive Web App (PWA) in Laravel – Zaigo Infotech Software Solutions

Let’s craft brilliance together!

Request a free consultation and get a no-obligation quote for your project within one working day.

Company-Logo

Error: Contact form not found.

Configure Progressive Web App (PWA) in Laravel

Laravel

Configure PWA in Laravel: Build an Installable, App-Like Experience

Progressive Web Applications (PWAs) enable web applications to deliver an app-like experience directly through the browser. With features such as offline access, installability, and improved performance through caching, PWAs are a valuable enhancement for modern Laravel applications.

This guide explains how to configure a PWA in Laravel using two approaches:

  1. Using a Composer package (quick setup)
  2. Manual implementation (full control)

Introduction to PWA

A Progressive Web App is a web application enhanced with modern browser capabilities to behave like a native application. It relies primarily on two components:

  • Web App Manifest (defines app metadata such as name, icons, theme)
  • Service Worker (handles caching, offline support, and background processes)

Prerequisites

Before proceeding, ensure the following:

  • Laravel project is already set up
  • Application is served over HTTPS (required for service workers)
  • Basic understanding of Blade templates and public assets

Method 1: Using Composer Package

This is the quickest way to enable PWA functionality in Laravel.

Step 1: Install Package

Run the following command:

composer require silviolleite/laravel-pwa

Step 2: Publish Configuration

php artisan vendor:publish --provider="LaravelPWA\Providers\LaravelPWAServiceProvider"

This will generate a configuration file:

config/laravelpwa.php

Step 3: Configure PWA Settings

Update the configuration file:

return [
    'name' => 'Zaigo Infotech',
    'short_name' => 'Zaigo',
    'start_url' => '/',
    'display' => 'standalone',
    'background_color' => '#ffffff',
    'theme_color' => '#0d6efd',
    'orientation'=> 'portrait',
    'status_bar'=> 'black',
    'icons' => [
        [
            'src' => '/images/icons/icon-192x192.png',
            'sizes' => '192x192',
            'type' => 'image/png'
        ],
        [
            'src' => '/images/icons/icon-512x512.png',
            'sizes' => '512x512',
            'type' => 'image/png'
        ]
    ]
];

Step 4: Add Icons

Place your icons inside:

public/images/icons/

Ensure you include at least:

  • 192×192
  • 512×512

Step 5: Include PWA Meta Tags

In your main Blade layout:

<head>
    @laravelPWA
</head>

Step 6: Verify Installation

Open your website in Chrome. If configured correctly:

  • You will see the install icon in the address bar
  • An install popup will appear

Method 2: Manual PWA Setup (Recommended for Full Control)

This approach provides better flexibility and understanding of how PWA works internally.


Step 1: Create Manifest File

Create a file:

public/manifest.json

Add the following content:

{
  "name": "Zaigo Infotech",
  "short_name": "Zaigo",
  "start_url": "/",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#0d6efd",
  "orientation": "portrait",
  "icons": [
    {
      "src": "/images/icons/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "/images/icons/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ]
}

Step 2: Link Manifest in Blade

Inside <head>:

<link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#0d6efd">

Step 3: Create Service Worker

Create a file:

public/service-worker.js

Example:

const CACHE_NAME = "zaigo-pwa-v1";
const urlsToCache = [
    "/",
];

self.addEventListener("install", event => {
    event.waitUntil(
        caches.open(CACHE_NAME)
            .then(cache => cache.addAll(urlsToCache))
    );
});

self.addEventListener("fetch", event => {
    event.respondWith(
        caches.match(event.request)
            .then(response => response || fetch(event.request))
    );
});

Step 4: Register Service Worker

Add this before closing </body>:

<script>
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);
    });
}
</script>

Step 5: Add Icons

Place icons in:

public/images/icons/

Step 6: Enable Install Prompt (Optional Enhancement)

To control install popup:

let deferredPrompt;

window.addEventListener('beforeinstallprompt', (e) => {
    e.preventDefault();
    deferredPrompt = e;

    // You can trigger this on button click
    document.getElementById('installBtn').style.display = 'block';
});

document.getElementById('installBtn').addEventListener('click', () => {
    deferredPrompt.prompt();
    deferredPrompt.userChoice.then(choiceResult => {
        deferredPrompt = null;
    });
});

Common Issues and Fixes

  • PWA not showing install option
    Ensure HTTPS is enabled and manifest is correctly linked.
  • Service worker not registering
    Verify file path and check browser console.
  • Icons not appearing
    Confirm correct sizes and file paths.

Conclusion

Implementing a PWA in Laravel enhances user experience by providing faster load times, offline capabilities, and installable web applications.

For quick integration, the Composer package is suitable. For production-grade applications where customization is required, the manual approach is recommended.

Can't find what you are looking for?

Post your query now, and we will get in touch with you soon!

    Want to start a project?

    Our team is ready to implement your ideas. Contact us now to discuss your roadmap!

    GET IN TOUCH

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    INDIA

    9thfloor, (9A & 9B) Sapna Trade Centre, 135,
    Old 109, Poonamallee High Rd, Egmore,
    Chennai, Tamil Nadu 600084

    +91 9884783216

    marketing@zaigoinfotech.com

    USA

    170 Post Rd #211, Fairfield,
    CT 06824,
    USA

    +1 904-672-8617

    sales@zaigoinfotech.com