force cache refresh?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

force cache refresh?

Post by D Oliveira » 2020-02-18 20:57

simple question, is there a way to force cache refresh for js files without requiring the user to clear it by himself?

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

Re: force cache refresh?

Post by jsetzer » 2020-02-18 21:40

Yes, wherever you request a CSS or JS file, pass any unique string as parameter, for example:

Code: Select all

mytheme.css?rnd=12345678abcdefg
or
myscript.min.js?tmp=112358
This makes every request for a remote resource unique.

Change that random code on every call using PHP or Javascript.

Doing it this way, the browser cannot find exactly that requested resource url in its cache. For the browser it is a completely different resource. In these cases the browser will request the file from the server and not from its cache, obviously, because exactly this url has not been cached before.

If you also mean AppGini's core scripts and style sheets, this becomes more difficult because the generated files do not pass any random string when requesting resources.

Please note that this leads to more traffic and will slow down the app - because you pass by the browser's caching. Loading from a remote machine over the network will be slower than reusing a file cached locally. This should not be a problem in intranet applications but may become more important for example on mobile devices connected via a low bandwidth network.

Best,
Jan
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 24.10 Revision 1579 + all AppGini Helper tools

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

Re: force cache refresh?

Post by D Oliveira » 2020-02-18 21:54

jsetzer wrote:
2020-02-18 21:40
Yes, wherever you request a CSS or JS file, pass any unique string as parameter, for example:

Code: Select all

mytheme.css?rnd=12345678abcdefg
or
myscript.min.js?tmp=112358
This makes every request for a remote resource unique.

Change that random code on every call using PHP or Javascript.

Doing it this way, the browser cannot find exactly that requested resource url in its cache. For the browser it is a completely different resource. In these cases the browser will request the file from the server and not from its cache, obviously, because exactly this url has not been cached before.

If you also mean AppGini's core scripts and style sheets, this becomes more difficult because the generated files do not pass any random string when requesting resources.

Please note that this leads to more traffic and will slow down the app - because you pass by the browser's caching. Loading from a remote machine over the network will be slower than reusing a file cached locally. This should not be a problem in intranet applications but may become more important for example on mobile devices connected via a low bandwidth network.

Best,
Jan
Excellent tip Jan, thank you, I do not need to constantly refresh the cache, but it comes in handy whenever updates need to take place, in that case I was referring specifically the tablename-dv.js file inside the hooks folder, once again, thanks for the tip!

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

Re: force cache refresh?

Post by jsetzer » 2020-02-18 21:59

Awesome, glad I could help!

Just want to add:
If you are versioning your scripts, you can also reference the version number, for example:

Code: Select all

<script src="myscript.min.js?v=2.31"></script>
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 24.10 Revision 1579 + all AppGini Helper tools

Post Reply