1

Possible Duplicate:
How to clear browser cache with php?

I have created a web application which uses so many javascript code. So sometimes it load cached javascript on client pc which is older version from current one. So I want to add a code using php or any other method which can clear the cached content before loading the page. How can I do that?

Thanks in advance.

Community
  • 1
  • 1
aslamdoctor
  • 3,753
  • 11
  • 53
  • 95
  • 1
    possible duplicates - http://stackoverflow.com/questions/1037249/how-to-clear-browser-cache-with-php, http://stackoverflow.com/questions/206783/when-does-browser-automatically-clear-javascript-cache – Christian P Oct 18 '11 at 07:33

3 Answers3

2

if you can access the web server, you can set the content expire time to current time, so that the browser will fetch a new version of contents from your web server.

For IIS's steps, view here.

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • 1
    You can use mod_expires (and .htaccess files) with Apache : http://httpd.apache.org/docs/2.0/mod/mod_expires.html – CD001 Oct 18 '11 at 07:49
1

You can add a random $_GET parameter - with a timestamp for example. Instead of

<script type="text/javascript" src="script.js"></script>

Do something like:

<script type="text/javascript" src="script.js?reload=1318923150"></script>
biphobe
  • 4,525
  • 3
  • 35
  • 46
  • 1
    The technique @firian describes above is called "revving". It's quite common in app these days as all of your assets can be concatenated, compressed and cached with a far future expires header. –  Oct 18 '11 at 07:38
0

You could call you javascript files using an additional GET parameter. like:

http://example.com/page1/myjs.js?page=page1
spicavigo
  • 4,116
  • 22
  • 28