Retry cancelled APIs on location change

Whenever the window location changes API calls called are canceled by the browser.
I am firing analytics events on-click of a button which also takes to a subdomain and refreshes the page, so there is a race condition now. Sometimes the event is resolved and sometimes it is canceled by the browser.
the possible workaround I found are as follows

  1. wait for the event to be resolved before redirecting
  2. store in local storage and fire on returning back
  3. pass the event to be fired as query param to the subdomain and fire it there

Is there a better solution for this ?

enter image description here

Source: Ask Javascript Questions

LEAVE A COMMENT