Jan Rüegg Jan Rüegg - 2 months ago 11
Javascript Question

location = "file.exe", show download size during download?

I use the following javascript snippet to let the user download a file when he clicks a button:

location = 'http://www.example.com/files/installer.exe'

The problem is that while it works, it doesn't show the file size while downloading (tested in Firefox on Windows).

Is there a way to tell the browser the size of the executable, so the user sees a progress bar while downloading?


Not from client-side JavaScript—the browser has no way to know the size of a remote resource if the server doesn't say.

You need a server-side fix: generate a valid Content-Length header. Web servers typically do it automatically. If yours doesn't, that possibly means you have a server-side script that sends the file but does not report its size.