1

I'm trying to cache API call which is handled by XMLHttpRequest with using Workbox. I successfully cached API calls in Cache Storage. However, the request to cached data fails when I switched to offline although the data is in Cache Storage. Then I replaced the method using XMLHttpRequest with fetch event and it pulled the cached data and renders the element in offline.

So, I would like to know whether there is a workaround to use XMLHttpRequest not fetch.

The reason I'm asking is that I am planning to cache API call for multiple many pages but most of the widgets in my workplace is using jQuery Ajax. I'm afraid that we need to replace the method Ajax with fetch one-by-one.

Bharti Rawat
  • 1,949
  • 21
  • 32
shinyatk
  • 855
  • 11
  • 28
  • 2
    You should be able to intercept XMLHttpRequest, unless it is a synchronous request - see https://stackoverflow.com/questions/35879844/can-service-workers-respond-to-synchronous-xhr-requests – Will Taylor May 31 '19 at 12:55
  • Thank you for the URL. That answers my question! – shinyatk Jun 01 '19 at 00:31

0 Answers0