• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Clear user browser cache/cookie using Java code  RSS feed

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I need to programmatically clear the user browser cache/cookie/temp files through the Java/J2EE code initially when the user hit the site for any transactions. So that there wont be any cache issue for the user to perform various transactions. Please let me know what is the best approach to do so?

Thanks.
 
Saloon Keeper
Posts: 10136
214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhh, what kind of cached information do you expect to interfere with your transactions?
 
Rithanya Laxmi
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are cases the user browser is having old JS or corrupted one in that case it wont allow the user to proceed with the transactions, in the case i want to clear the user browser cache through application and not ask the user to clear it manually.
 
Stephan van Hulst
Saloon Keeper
Posts: 10136
214
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use cache busting: Append a version query parameter to the links to your JavaScript files: https://example.com/myapplication/scripts/foo.js?v=1.2.3
 
Rithanya Laxmi
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephan, this is for the JS & CSS we can use cache busting which is application specific, how we can programmatically ensure to delete the user browser "temp" internet files?
 
Stephan van Hulst
Saloon Keeper
Posts: 10136
214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I *think* you can use the Clear-Site-Data response header for this, but how are you going to determine when to send it?
 
Rithanya Laxmi
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephen, few queries :

1. How to make use of the clear-site-data in javascript code to clear the user browser cache/temp files? any samples available?
2. How we can find the JS files in the user browser is corrupted or  exceed the limit and then take action by deleting/removing it using clear-site-data? is there any way we will get it from Http headers?

Please let me know.
 
Master Rancher
Posts: 4042
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't a hard reload force a refresh from the server, at least for the things you'd be interested in?

Document.location.reload(true)?
 
Stephan van Hulst
Saloon Keeper
Posts: 10136
214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rithanya Laxmi wrote:1. How to make use of the clear-site-data in javascript code to clear the user browser cache/temp files? any samples available?


You don't. It's a response header that gets sent when you load a page. I suggested doing this with a response header, because how are you going to fix your corrupt JS from your JS if your JS is corrupt?

2. How we can find the JS files in the user browser is corrupted or  exceed the limit and then take action by deleting/removing it using clear-site-data? is there any way we will get it from Http headers?


Well, that was exactly the question that I posed YOU in my last post. How are you going to detect that you need to clear the cache? The only reliable method that doesn't completely disable caching in the first place is to let the user browse to a certain URL that will clear the cache for them. But then the user might as well just clear the browser cookies/cache manually.

Why don't you just try the cache busting solution, and then return to us if that solution doesn't solve all your problems?
 
Squanch that. And squanch this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!