ProAnswers.org

Can I check whether a page is cached by the browser?

1 Like

There is no direct Javascript interface for checking the contents of the browser’s cache. It would be a security hazard if you were able to probe the contents of the users’ file system. But there are indirect techniques you can use to track pages people have visited on your site, which are likely to be cached.

The key way to record that an HTML document or image has loaded is the onload event that is triggered when the download is complete. These Javascript events can be assigned an event handler function to be called when the event occurs. The event handler function may then store the page information in a cookie.

onload=“logPage(‘Example.htm’);” >

Though you can be sure that documents and images have downloaded, there is no certainty that they are actually cached, browsers are not obliged to do so and it is possible to disable caching. Still, your Javascript application can make an [b]assumption[/b] that these assets are cached provided it does not [b]rely[/b] on the fact, and deals with the possibility that they are not.