'How to fetch data from browser cache?

When we open a specific website the browser caches the files and when next time we open the same website - Somehow browser fetches it from cache. I understand that the .Cache directory holds the information (probably in an encrypted way). I need to know is there any method or way by which we can extract the cached files (from some other website).

enter image description here

For example: Website A has cached files X. Now when we open website B in new tab somehow we should list down what are all the files which are cached in the browser currently.

If someone can help or guide where can we find the relevant document on this topic will be helpful?

Thanks!



Solution 1:[1]

You can use fetch for fetching the data from the browser cache, the first argument will have the name of the data resource you are looking for and the second argument specifies that the data should be fetched from the cache.

 fetch("some.json", {cache: "force-cache"})
    .then(function(response)

Solution 2:[2]

If you want to ONLY pull from the cache, you can use "only-if-cached" for the cache property in the fetch:

fetch("some.json", {cache: "only-if-cached"})
  .then(data => console.log(data))
  .catch(err => console.log(err));

If there is no match in the cache, the browser responds with a 504 Gateway timeout.

You can find more information here: only-if-cached

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nikhil Singh
Solution 2 william zona