I have a PDF export that takes a while to create the PDF. I want the user to be able to click the export link and be presented with a download dialog right away. This way they can start the download and just wait for it to complete. Instead of clicking the link, wait for the generation and then wait for the download again.
Here's a very simple example in PHP:
<?php
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=test.pdf');
flush();
// time consuming PDF creation happens here
sleep(15);
echo 'pdf contents would be here';
The idea is to send the appropriate headers, flush() them to the browser, slowly create the PDF and finally send it to the browser.
This works perfectly in chrome. The Download Dialog pops up immeadiately and the sleep is part of the download waiting time.
In Firefox and InternetExplorer this does not work. Those browsers wait the full 15 seconds before showing the download dialog.
Any idea how to make the download dialog pop up immeadiately would be greatly appreciated.