How to refresh the included .js file without refresh button

Posted on 2005-05-06
Last Modified: 2013-11-18
I have common.js file which included in the all the JSPs. When i am changing in any scripts need to refresh or need to clear the cache in iternet explorer.

We are using the below peice of code for clearing the cache. But its not working for .js files.

Could any one tell us any solution to clear the cache.

response.setHeader( "Expires", "Sat, 6 May 1995 12:00:00 GMT" );
response.setHeader( "Cache-Control", "no-store, no-cache, must-revalidate" );
 response.addHeader( "Cache-Control", "post-check=0, pre-check=0" );
 response.setHeader( "Pragma", "no-cache" );
Question by:ramsharma23
    LVL 25

    Accepted Solution

    Try this

     Try this:

    <script  id = "scr"></script>

    document.getElementById('scr').src = "";
    alert("Loaded external file");
    LVL 11

    Expert Comment

    I guess it's same what u have above,
    but give it a shot...

    response.setDateHeader("Expires", 0);
    LVL 32

    Expert Comment

    Where do you put these lines

    response.setHeader( "Expires", "Sat, 6 May 1995 12:00:00 GMT" );
    response.setHeader( "Cache-Control", "no-store, no-cache, must-revalidate" );
     response.addHeader( "Cache-Control", "post-check=0, pre-check=0" );
     response.setHeader( "Pragma", "no-cache" );


    Are they in both your HTML and JS files, or only in the HTML files.

    If they are only in the HTML files, maybe you should put them at the top of the js files as well.

    Note: This requires that JS files are parsed by your server side script.

    LVL 25

    Assisted Solution


    it's much simpler as you think. Just add a unique number: include.js?56467890074567

    with pure javascript would be:
    document.write("<scr"+"ipt src='"+((new Date()).valueOf())+"'></scr"+"ipt>");

    since you are using JSP, you can do it on server and not always, just if you need.
    LVL 17

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

    I will leave the following recommendation for this question in the Cleanup topic area:
        Split between archrajan and devic

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    EE Cleanup Volunteer

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Shoutout to Emily Plummer ( for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now