1

I was wondering if there was a way to use js to find out the file size for a file that i'm linking to a webpage.

I want to make it so that on hovering over the download link, a modal box pops up saying the file size of the file

3
  • look this API developer.mozilla.org/en-US/docs/Web/API/FileList File has size property Commented Feb 10, 2018 at 23:51
  • 1
    @Yurii That is for file uploads. Commented Feb 10, 2018 at 23:52
  • @AurelBílý you are right, didn't catch the message. Commented Feb 10, 2018 at 23:54

1 Answer 1

1

No, for that to happen with Javascript only the browser would have to download the file first to check its size, which beats the purpose. There is a HEAD method in HTTP, though it may not be supported easily (either by the browser or the server).

In general, when servers show filesizes, they are pre-calculated (and ideally cached) server-side, so using PHP / node.js / Django / whatever back-end. It is possible to retrieve this information asynchronously using AJAX triggered by mouse hover. However, this is probably much more wasteful (bandwidth-wise, code-wise) than simply sending the filesize attached with any file link – the filesize is just a couple of bytes anyway.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.