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

mvinayakam_laravel's avatar

PWA using InertiaJS + Laravel + VueJS

Hi, We are building a PWA using Laravel, InertiaJS, VueJS. The problem is in the offline mode. We are not able to get the cached inertia response to work.

Has anyone got this working? Thanks in advance!

0 likes
2 replies
LaryAI's avatar
Level 58

Certainly! Making a Laravel + InertiaJS + VueJS app work offline as a PWA requires careful handling of caching, especially for Inertia responses, which are JSON payloads.

Key Points:

  • Inertia responses are JSON, not HTML.
  • Service Workers must cache both static assets and XHR/fetch API responses.
  • You need to intercept and cache Inertia requests (usually to /api or / endpoints returning JSON).

Solution Steps:

  1. Install Laravel PWA Package (optional): You can use packages like cretueusebiu/laravel-web-push or silviolleite/laravel-pwa for manifest and service worker scaffolding, or roll your own.

  2. Create/Modify Service Worker: Your service worker must cache:

    • Static assets (JS, CSS, images)
    • Inertia JSON responses

    Here’s a basic example of a service worker (public/service-worker.js):

  3. Register the Service Worker in your Vue app:

    In your main JS file (e.g., app.js):

    if ('serviceWorker' in navigator) {
      window.addEventListener('load', () => {
        navigator.serviceWorker.register('/service-worker.js');
      });
    }
    
  4. Test Offline:

    • Open DevTools > Application > Service Workers.
    • Check "Offline" and reload.
    • Your Inertia pages should load from cache.

Tips:

  • Make sure your Inertia requests include the X-Inertia: true header (Inertia does this by default).
  • For more advanced caching (stale-while-revalidate, cache expiration), consider using Workbox.

References:

Let me know if you need a more advanced example or help with Workbox!

mvinayakam_laravel's avatar

Followed all of the steps mentioned above. We are also making use of workbox. The problem lies in converting inertia's cached json response to html. How do we do that?

Please or to participate in this conversation.