Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Chrome spend time "downloading" content from cache?

I am serving static content intended to be cached by the browser indefinitely. Chrome is caching it as expected, but is still spending time "downloading" it. I am using Chrome 46.0.2490.71.

Chrome Network Tab

As you can see, the content is being served from cache, but still takes 68ms for content download. This is causing the svg images to flash in on every page load, even though the file is cached.

Here is the relevant timeline information from a page load in Incognito mode:

Chrome Timeline Tab

The "Total Time" and "Event Time" fields for each of those events is zero. Replicating this with the file served locally (but still from cache) the "Receive Data" event is only seen once.

A few interesting points to note:

  • Serving the same file from my local machine, with the same encoding, does not produce the same download delay.
  • Switching to Incognito mode (no extensions) halves the download delay, but does not eliminate it.
  • It is quicker to refresh the page, as it appears to take less time to receive a 304 response from the server than to merely load it from cache.
  • Closing the dev tools does not appear to have any effect on the delay.
  • IE 11, Edge, and Firefox 41 do not show any delay.

What possible causes could there be?

like image 608
dlras2 Avatar asked Oct 21 '15 04:10

dlras2


People also ask

Why does Google Chrome keep downloading files?

Chrome is trying to do something with them, and that's why you are getting that message. I've had that same thing happen to me before. Try clearing all your download history, and browsing data. (Settings >>> Privacy and Security >>> Clear Browsing Data).

Does clearing cache speed up Chrome?

Clear your browsing data As you visit more and more websites, these pieces of data accumulate in Chrome and can slow the browser down. Thankfully, the solution to this is easy: clear your cache. To do this, simply access your browsing history by entering chrome://history on your address bar.

How long does Chrome keep cached files?

The default is infinite. As newer files are added to the cache, old ones are purged to make space. The file won't actually stay in the cache for ever.

How does Google Chrome's cache work?

Well, Chrome's cache is a database, and that database is also compressed to save space. When you retrieve a document from cache, the price of that retrieval is not zero. Chrome has to look up the item in the cache database, and then inflate that entry into memory so Chrome can work with it.

Why is Google Chrome asking me to download it?

If you look in the corner of your screen when searching with Google, it sometimes asks you to download Chrome for optimised performance. It also sometimes asks you, even when you have Chrome, to make Chrome your default browser, as well as ads in Gmail and YouTube. Layout of Chrome.

Why do my downloads keep crashing on Chrome?

‘Downloads crash Chrome’ glitch is troubling both Windows and Mac users. The problem is Chrome-specific as users have confirmed they face no such issue with other browsers. And not to miss, the glitch reportedly creeped in after Chrome update v73 and continues to persist even on v74.

Why do I see a Chrome icon when I download files?

That is because your machine has Chrome set as the default application to launch from that filetype. If your default browser is Chrome, that makes sense. And any file you download that is HTM or HTML at least, will show a Chrome icon.


Video Answer


2 Answers

So this has to do with the way caching works in Chrome. I don't have personal experience with Chrome's codebase, but I do know a bit about the theory of it. (I also found a reference to Chrome's cache implementation here for the more curious: chromium disk cache)

For reference, here is a screenshot of my loading your actual Stack Overflow question in Chrome with the Network panel open and the Network Throttling option set to "Offline". Notice that every single entry in this list is got from cache!

Imgur screencap

You'll also notice that Chrome is spending time "downloading" every file. Why is this? Well, Chrome's cache is a database, and that database is also compressed to save space. When you retrieve a document from cache, the price of that retrieval is not zero. Chrome has to look up the item in the cache database, and then inflate that entry into memory so Chrome can work with it. I don't know the exact details concerning how the Network chrome-dev-tools panel shows the times, but I would guess that getting that file from disk, uncompressing it, and then parsing and working with the result is what you're seeing reflected in "Time downloaded."

I can't comment on why other browsers don't also have this delay, since I don't have a lot of experience with them. It might be that they either use a more efficient method of getting things from cache (possible), or it could be that they keep the cache in memory at all times (unlikely), or that they're skipping some of the integrity checks Chrome is making on cache data (possible)

like image 104
MaxML Avatar answered Oct 22 '22 01:10

MaxML


I came across same issue. I implemented PDF Download functionality. on clicking download link I got response in around 260 ms but downloads starts after 10 seconds on chrome.

FIX:- I analysed that my windows system was 64 bit and chrome was 32 bit. After upgrading chrome to 64 bit this issue was resolved. I found resolution at https://bugs.chromium.org/p/chromium/issues/detail?id=103737

like image 30
Shahzad Avatar answered Oct 22 '22 00:10

Shahzad