How to programmatically empty browser cache?

There’s no way a browser will let you clear its cache. It would be a huge security issue if that were possible. This could be very easily abused – the minute a browser supports such a “feature” will be the minute I uninstall it from my computer.

What you can do is to tell it not to cache your page, by sending the appropriate headers or using these meta tags:

<meta http-equiv='cache-control' content="no-cache">
<meta http-equiv='expires' content="0">
<meta http-equiv='pragma' content="no-cache">

You might also want to consider turning off auto-complete on form fields, although I’m afraid there’s a standard way to do it (see this question).

Regardless, I would like to point out that if you are working with sensitive data you should be using SSL. If you aren’t using SSL, anyone with access to the network can sniff network traffic and easily see what your user is seeing.

Using SSL also makes some browsers not use caching unless explicitly told to. See this question.

Leave a Comment