[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 870
  • Last Modified:

How to refresh the included .js file without refresh button

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" );
0
ramsharma23
Asked:
ramsharma23
2 Solutions
 
archrajanCommented:
Try this

 Try this:

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

<script>
document.getElementById('scr').src = "http://foo.com/lib.js";
alert("Loaded external file");
</script>
0
 
raj3060Commented:
I guess it's same what u have above,
but give it a shot...

response.setHeader("Cache-Control","no-cache");
response.setHeader("Cache-Control","no-store");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma","no-cache");
0
 
BatalfCommented:
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.

Batalf
0
 
devicCommented:
ramsharma23,

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

with pure javascript would be:
=====================
<script>
document.write("<scr"+"ipt src='http://www.sembel.net/expexc/js/script/include.js?"+((new Date()).valueOf())+"'></scr"+"ipt>");
</script>


since you are using JSP, you can do it on server and not always, just if you need.
0
 
Cem TürkSenior Software EngineerCommented:
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.

cem_turk
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now