I asked pretty much the same question a long time ago (here) and the notable T. J. Crowder suggested an awesome solution. The client (the page) submits an extra parameter when asking for the file. The extra parameter should be some random string. Then, you launch your modal "Wait ..." dialog.
Now, from the server, when you prepare the response, you set a cookie to the value of that extra param. The client, in turn, should start an interval timer that just looks at document.cookie
every 100 milliseconds or so, checking for that random value. As soon as the cookie contains the random value, then you know that the HTTP response has arrived from the server! At that point, you can hide the modal dialog or whatever.