I found myself searching for this question and came to a solution that was aided in part by other stackoverflow threads.
The context:
I have a flask app that processes large datasets (most of this is done through Dash and Plotly, which I highly recommend).
I have one page where the user can request a downloads of particular parts of the dataset. The files are generated dynamically and can sometimes be large.
The user experience problem:
When users click button/link requesting the file download, the page can sit for up to 10 seconds while flask prepares the dynamically generated file, and then ultimately responds to the request with send_file and the download is initiated. This period of waiting is confusing for the user, and the experience would be aided with a spinner to indicate that the request was received.
The technical problem:
The issue is that when you point the browser window to the new file url, you lose control of how the webpage is displayed... in other words it's easy to start the spinner - stopping it is the crux. This topic has been discussed in many other threads here, but one solution stood out and integrated well with the flask send_file routine. I tried a number of other solutions before settling on the one I will post under "answers".
Related question (s)
This implementation may be helpful for someone else because it's specific to flask, but the question is similar to this thread: Detect when browser receives file download
The solution, however, mostly derives from this thread: Download a file by jQuery.Ajax
One benefit is that it retains the dynamic naming conventions for the file that you define in flask by appending a header to the response. Overall, though, its nothing groundbreaking, just a working solution to a more specific question. It's flask, though, so there are surely a million other ways to get it done.