Programmatically Clear Browser Cache

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
rpierce
Veteran Member
Posts: 304
Joined: 2018-11-26 13:55
Location: Washington State

Programmatically Clear Browser Cache

Post by rpierce » 2024-12-06 19:50

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

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1944
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Programmatically Clear Browser Cache

Post by jsetzer » 2024-12-06 21:23

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 25.10 + all AppGini Helper tools

rpierce
Veteran Member
Posts: 304
Joined: 2018-11-26 13:55
Location: Washington State

Re: Programmatically Clear Browser Cache

Post by rpierce » 2024-12-06 23:12

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

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1944
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Programmatically Clear Browser Cache

Post by jsetzer » 2024-12-07 04:48

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 25.10 + all AppGini Helper tools

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 357
Joined: 2018-03-04 09:30
Location: David

Re: Programmatically Clear Browser Cache

Post by D Oliveira » 2024-12-08 17:37

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.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1944
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Programmatically Clear Browser Cache

Post by jsetzer » 2024-12-09 12:25

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!
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 25.10 + all AppGini Helper tools

Post Reply