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

133
Views
¿Cómo verificar si React PWA usa la última versión?

Me gustaría mostrarle a mi usuario que hay una actualización disponible. Por lo tanto, necesito saber cómo verificar si ya usa la última versión.

Actualmente configuro un elemento en localStorage llamado "updateAvailable" tan pronto como el serviceWorker me dice que hay una nueva versión disponible. Eso funciona bien.

Sin embargo, lo que no funciona bien es cuando me gustaría configurar "updateAvailable" en falso. El elemento no está configurado en localStorage.

¿Cómo configuro este elemento en localStorage cuando se usa la última versión de mi PWA?

 function registerValidSW(swUrl: string, config?: Config) { console.log("test 5") navigator.serviceWorker .register(swUrl) .then(registration => { registration.onupdatefound = () => { const installingWorker = registration.installing; if (installingWorker == null) { return; } installingWorker.onstatechange = () => { if (installingWorker.state === 'installed') { if (navigator.serviceWorker.controller) { // At this point, the updated precached content has been fetched, // but the previous service worker will still serve the older // content until all client tabs are closed. console.log( 'New content is available and will be used when all ' + 'tabs for this page are closed. See [hidden link]' ); localStorage.setItem("updateAvailable", "true") // Execute callback if (config && config.onUpdate) { config.onUpdate(registration); } } else { // At this point, everything has been precached. // It's the perfect time to display a // "Content is cached for offline use." message. console.log('Content is cached for offline use.'); localStorage.setItem("updateAvailable", "false") // Execute callback if (config && config.onSuccess) { config.onSuccess(registration); } } } }; }; }) .catch(error => { console.error('Error during service worker registration:', error); }); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

ese bloque de código solo se ejecuta en el evento 'onupdatefound'.

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!