ubuntu – Nginx – Why empty files take longer time to load?

Basic set up with simple location block

location {
   root /my/folder/

Then i created 4 files

  • index.html (empty)
  • abc.json (with only 2 curly brackets)
  • empty.png (not a single space in file)
  • notempty.png (same as empty.png but i added a single space inside the file)

What I did was doing a basic javascript fetch.

    const results = Promise.all((
        fetch(`${host}`, { mode: 'no-cors'}),
        fetch(`${host2}`, { mode: 'no-cors'}),
        fetch(`${host3}`, { mode: 'no-cors'}),
        fetch(`${host4}`, { mode: 'no-cors'}),

I refresh the page a few times to see the fetches, and the fetch results in screenshot below

Notice both the completely empty files takes 60-70ms to response while those with single space returns much faster.

enter image description here

My question

Why does a completely empty file, takes a longer time to download, then a file with e.g. a single space or curly brackets?

Why am I doing this?

My server is currently serving images, and i have cache enabled. The same file is always being downloaded by browsers at about 70-100ms, while if I use a CDN in the same location, it’s around 10-20ms.

I am trying to find out how nginx behaves and where are the bottleneck, and why nginx is not responding as fast as a cdn when it can achine 10-20ms for small byte files.

In case you are interested in the timings. (the difference is in the content download though both are similar in side)

enter image description here

enter image description here