Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

78
Views
Relay information to the service worker on install

I have a PWA with multiple different languages and would like to cache only language specific files on install. I can't find out a way to communicate the language to the service worker during install. Ideas on how I could do it?

My js code to initiate the service worker:

navigator.serviceWorker.register('../service-worker.js', { scope: '/' }).then((reg) => {
    console.log('Service worker registered successfully.', reg);
    registration = reg;
}).catch(function (e) {
    console.error('Error during service worker registration:', e);
});

My code in the service-worker.js:

self.addEventListener('install', function(event) {
    messageAllClients('Event-Install');
    // Perform install steps
    event.waitUntil(
        caches.open(CACHE_NAME).then(function(cache) {
            messageAllClients('Language detected by the service worker: '+language);
            messageAllClients('Pre-caching offline page');
            return cache.addAll(FILES_TO_CACHE);
        })
    );
    self.skipWaiting();
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Variables can be relayed to the service worker during install via GET attributes, as @JeffPosnick pointed out in the comment.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!