0

Is there a reliable to way to check if a particular asset was loaded from cache or from the network?

The only way I found so far is to set a threshold like 10ms and check the loading duration, however it seems that it might not be always accurate.

UPDATE

I need to do that for monitoring/debugging purposes and possible optimizations depending on what I see in the metrics

tobsob
  • 602
  • 9
  • 22
Leo
  • 1,683
  • 2
  • 20
  • 25
  • I don't believe there is. Can I ask why you need to know? If the server file is newer than the cached file, it should automatically be delivered. – Scott Marcus Aug 13 '19 at 19:31
  • you mean for debugging purposes or you want to determine it programmatically with javascript on a promise for example? – MKougiouris Aug 13 '19 at 19:31
  • @zfrisch the referred question seems to be about html whole page cache rather than about particular assets – Leo Aug 13 '19 at 19:45
  • "10ms and check the loading duration, however it seems that it might not be always accurate" This will never be reliable -> slow machine, crappy code, very fast internet. Don't use it. Do this instead https://stackoverflow.com/a/265125/4194436 – Michelangelo Aug 13 '19 at 19:49
  • I think there is no way, But instead of regular request you can retrieve them as GET/POST methods, that these ones never been cached! I got the way and when ever need to cache them, They will be cached in the DOM with JS. – Mamrezo Aug 13 '19 at 19:52
  • @Michelangelo, Yes that is a good way, of course need good enough knowledge's to implement them, But retrieve such resources is most reliable with GET/POST. for example: `http://xyz/someresource.something` may be cached even with no-cache or other headers! But `http://xyz/ret.[php/asp/aspx...]?res=someresource` will never cache! – Mamrezo Aug 13 '19 at 19:59

0 Answers0