Why chrome cached requests are taking time?

2019-06-22 06:31发布

Even though Chrome is caching static files (JS, images, etc.,) in the Network tab, these files are taking sometime as shown in the below picture.enter image description here

Where as many of the cached files are loading in just 0ms. Can someone please tell me even though the files are loading from cache, why are they loading in >0ms?

2条回答
仙女界的扛把子
2楼-- · 2019-06-22 07:23

Oddly, timings in Chrome are a bit... quirky... the time is not purely network time. If the JS engine gets blocked somehow, it is included in that total time...

enter image description here

If you hit this issue go to "timeline" tab and record a full timeline.

查看更多
相关推荐>>
3楼-- · 2019-06-22 07:24

At first glance, it does look quite strange to see Chrome spending time downloading resources even though they are coming from the cache. It's not the time spent downloading from a web server you're seeing. Rather, I believe it is the time spent downloading from a local database cache.

The retrieval of any data has some amount of cost involved. The resources are essentially stored in a database in Chrome, and to retrieve data requires a lookup, which is not instant. As well as looking up the data in a table, there is likely some processing involved to push the correct data into memory, since the data is not stored exactly how it is going to be used. It is likely to be compressed, and decompressing data can be a slow process.

You can see in the Network tab that, although it appears to take 0 ms to retrieve some resources, when you look at the Timings tab, you will see that it is actually rounded down. For example, I see both 0.08 ms stalled and 0.02 ms download in the request below, despite it showing 0 ms in the grid.

Not instant

Update:

I looked further into this and found that Chrome Extensions seem to have an effect on the retrieval times from both the cache and the web, particularly ones that inject content into the page. Adblock seems to be the cause of some delay for me - explanation above still very much applies for the rest.

查看更多
登录 后发表回答