dev-resources.site
for different kinds of informations.
Downloading the same file 102+ times
Have YOU ever tried downloading the same file 102+ times in your favorite browser? Do you know what happens on the 102nd time? š
I do. The answer is ... it depends š It varies between browsers and itās a bit of a surprise.
Before I show you the screenshots, let me first tell you a short story about how I ended up in the ālets-download-this-file-102-timesā rabbit hole so bear with me.
I work as a software developer and one day I got a message from a colleague asking something about a new feature. She sent me a link to an issue. There was a screenshot that caught my attention. It looked very much like the one below.
At the time the fileās name was hardcoded to āReport.zipā. So seeing āReport.zipā, āReport (1).zipā or āReport (42).zipā was to be expected. Instead of a counter, I was suprised to see a timestamp. Where did that come from? It was absolutely not in the code. My colleague didnāt manually add it either. Something was not right. And from here on the rabbit hole got deeper and deeper. š°
āA browser setting!ā - I thought. It was rulled out quite quickly because she didnāt remember changing any settings. We were looking in Edge because thatās the browser she uses. Besides, such a setting does not exist, I later found out.
āWell, then maybe the browser added it automatically. But at what point?ā I started searching on Google, going through different web pages, StackOverflow posts and forums. The more I searched, the more curious I became to figure this out. Then finally - FINALLY - a reply to a Reddit post gave me a pretty strong hint.
But was that still the case? There was only one way to find out. š
Fired up Edge and started downloading.
1, 2, 3, ... 10, ... 42, ... 99 times.
Then something magical šŖ happened the 102nd time! Instead of bumping a number, Edge added a timestamp šÆ Bingo! š The mystery was solved. That explained it.
So to make this more scientific, and for the purpose of this post, I decided to repeat the exercise in other browsers. Here are some screenshots.
Edge
Chrome
Firefox
Firefox just continues with bumping the counter. No timestamp here. Also note that thereās no space between the fileās name and the counter in parenthesis, as is the case in Edge/Chrome.
Update 2025-01-14
After publishing this post I got curious about the behaviour in Edge/Chrome. Since both browsers are Chromium-based, which is open source, I could, in theory, just look it up in the code. I didnāt know what to look for. So I asked on Bluesky. Kevin Doyon replied with a link to a method which is responsible for generating a unique filename. Using the āBlameā button at the top of the file revealed where each line of code came from. That led me to this commit which describes why the timestamp is added to the filename.
Seems like this is the end of it. Finally peace šļø
What a TIL!
Thanks for reading thus far. Hope you learned something new. See you in another post š
P.S. If you want to try it yourself, Iāve prepared a zip with an empty text file. Go ahead and download it. 102 times, of course.
Or you can quickly put together a simple demo by linking to a local file.
<a href="./fancy.zip" download>Download</a>
Featured ones: