Back in 2011, I answered a StackOverflow question. The question boils down to showing different content on the web page when the user has started a download. Using an event listener on the link to the download doesn’t work, because the download might be delayed because it is generated dynamically. The page, however, should update as soon as the download actually starts.
My answer back then was polling: Log the download request in a server-side database. The client page should poll the server and ask whether the download link was accessed. Besides polling, one could also use long-lived HTTP connections, or HTTP/2 push methods. When implementing this solution, one has to keep track which user has accessed the download link.
However, I think there is a better option:
- The reply to the download request could set a cookie, e.g.,
could poll the browser’s cookie storage, to check whether the
download_startedcookie is there.
The advantage of this solution is that it does not involve expensive server polling.
This might also interest you