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

208
Views
¿Por qué esta lógica de trabajador de servicio no funciona?

Tengo el siguiente trabajador de servicio escrito en TypeScript:

 self.addEventListener("fetch", (event: any) => { if (event.request.method == "POST") { event.respondWith( fetch(event.request).catch(error => { return caches.match(event.request); }) ); } else { event.respondWith( caches.match(event.request).then(cachedResponse => { // It can update the cache to serve updated content on the next request return cachedResponse || fetch(event.request); }) ); } });

Lo que quiero que haga es que si hay una solicitud POST en la página, use una estrategia de almacenamiento en caché primero en la red (obtener de la red).

Si no hay ningún cambio (no POST), use la primera estrategia de caché (obtener desde caché).

El tema es que no funciona. Nunca se recuperará de la red. También he intentado volver en POST así:

 self.addEventListener("fetch", (event: any) => { if (event.request.method == "POST") return; event.respondWith( caches.match(event.request).then(cachedResponse => { // It can update the cache to serve updated content on the next request return cachedResponse || fetch(event.request); }) ); });

¿Qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
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!