Page 1 of 1
Programmatically Clear Browser Cache
Posted: 2024-12-06 19:50
by rpierce
Hi all,
Does anyone know of a way to cause the browser to clear cache programmatically? I've been using the Mass Update plugin in my app and find that frequently the functions don't work if the browser cache is not cleared. If I press Control+Shift+Refresh browser then the function will work. I'm wondering if I could include some code somewhere that would automatically clear the browser cache when a page is accessed?
Thanks for any help.
Ray
Re: Programmatically Clear Browser Cache
Posted: 2024-12-06 21:23
by jsetzer
I think for security reasons it's impossible to force client side updates skipping cache from a server-side script.
If possible, when including scripts or stylesheets use a unique filename. You may include a version number or a timestamp.
myscript.js?v=20241206221957
I'm doing this from time to time and a while ago I've asked Ahmed to implement it for hooks. I think for -dv and -tv hooks it's implemented since latest version.
If someone knows a solution, this would really help.
Re: Programmatically Clear Browser Cache
Posted: 2024-12-06 23:12
by rpierce
Hi Jan,
In searching the web I find that you could potentially insert Meta tags into a page to prevent caching. Is there a way to test this out by forcing the tags into the generated pages in AppGini??
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
Thanks,
Ray
Re: Programmatically Clear Browser Cache
Posted: 2024-12-07 04:48
by jsetzer
As far as I know different browsers behave differently, but maybe I have missed something.
If anyone here could provide a browser independent solution, I'd be happy.
For performance reasons, instead of completely disabling caching I would prefer controlling certain files like certain scripts and certain stylesheets.
Re: Programmatically Clear Browser Cache
Posted: 2024-12-08 17:37
by D Oliveira
Client side caching should be considered outside of your control, you could pass a timestamp to load the js file like Jan mentioned `?id=123+timestamp()` OR if you truly wanna have control on that data you can save it on the php session a trigger param and manipulate via server side what gets rendered/loaded by invalidating the cache only when the session var changes because that would change the param being passed.
Re: Programmatically Clear Browser Cache
Posted: 2024-12-09 12:25
by jsetzer
By the way: by chance I've seen that, in deed, AppGini nowadays appends a file timestamp when lazy loading javascripts:
TV:
<script src="hooks/tasks-tv.js?1733732438"></script>
DV:
<script src="hooks/tasks-dv.js?1733641674"></script>
That's a big step forward, if you ask me!
Thank you, Ahmed!