andersonbd1
andersonbd1

Reputation: 5416

why are chrome and firefox are 10x slower than curl at downloading a super small javascript file?

I work on a web application in which the dev environment loads about 500 js files from a local web server (I've tried both IIS and apache). These files are optimized in prod, but for development that's what we have. I know there are other strategic options that might prevent the need to load so many js files, but that's currently out of my hands. What I'd like to do is speed up these requests. Am I crazy to think that each of these requests could only take 10ms, so that the whole request could take 5s (10ms * 500 requests)? Currently both chrome and firefox are reporting that these requests take about 100ms (even for 304s).

I took this down to the smallest common denominator and created a 1 line js file. I issue a request to this file through firefox and chrome and each report that it takes >100ms. What's odd, though, is that when I make the same request from curl, it only takes 5ms-ish:

$ curl 'http://10.222.139.56:81/js/ben.js' -o /dev/null -w '%{time_total}'
0.005

What gives? I would think the curl number is correct? Why are chrome and firefox taking longer?

Upvotes: 2

Views: 3173

Answers (2)

Johann
Johann

Reputation: 4373

The answer for me was simple: cookies.

On a single json file served as "Content-Type:application/json", Chrome's network tab consistently showed ~1400ms, while curl was ~300ms (even with a browser User-Agent set). The browser should have had little need to parse this as I disabled my pretty-printing plugins, and had "Disable cache" checked in Chrome's Dev Tools.

Finally I tried it in an incognito window and saw the same time results as Curl. I then went back to the original window and deleted cookies, nothing else, and got the same speed increase. I finally realized that my web application uses a specific authentication cookie in a request to another service which validates it.

Upvotes: 1

Mike Clark
Mike Clark

Reputation: 11979

My guess would be that for each js file loaded by Firefox and Chrome, the reported time includes the browsers parsing, caching, etc, of the file. Even a one-liner file is going to take a small amount of work to process. On the other hand, curl just pulls down the content and saves to disk or stdout. That operation is much faster.

Upvotes: 3

Related Questions