Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

325
Visualizações
How can I use manifest.mix.js to generate a service worker for offline?

I'm using laravel-mix-workbox to bundle and create a service worker. The service worker is running as expected, but there is apparently no precache files because it doesn't work offline (no content when offline after a reload).

Stack: Laravel 8, Vue 2, Workbox 6, Laravel-mix 6

// webpack.mix.js
const mix = require('laravel-mix');
require('laravel-mix-workbox');

mix.js('resources/js/app.js', 'public/js')
    .vue()
    .sass('resources/sass/app.scss', 'public/css')
    .sourceMaps(false)
    .generateSW()

here's what I tried:

// app.js
if ('serviceWorker' in navigator) {
    const wb = new Workbox('/service-worker.js')

    wb.addEventListener('install', (event) => {
        event.waitUntil(caches.open('v1').then(cache => {
            return cache.addAll([
                '/',
                '/index.html',
                '/favicon.ico',
                '/img/app_bar_text.jpg',
 //             (etc...)
            ])
        }))
    })

    wb.addEventListener('fetch', event => {
        event.respondWith(caches.match(event.request).then(response => {
            if (response)
                return response;
            return fetch(event.request)
        }))
    })

    window.addEventListener('load', async () => {
        await wb.register('service-worker.js')
    })
}

But, the generated service worker does not include any files I specify and no content when offline.

Do I have to explicitly list every offline file? Should this list of cached files (urls) go in app.js or webpack.mix.js? If webpack.mix.js, then how?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda