force cache refresh?
- D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
force cache refresh?
simple question, is there a way to force cache refresh for js files without requiring the user to clear it by himself?
Re: force cache refresh?
Yes, wherever you request a CSS or JS file, pass any unique string as parameter, for example:
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
Code: Select all
mytheme.css?rnd=12345678abcdefg
or
myscript.min.js?tmp=112358
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
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
- D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Re: force cache refresh?
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!jsetzer wrote: ↑2020-02-18 21:40Yes, wherever you request a CSS or JS file, pass any unique string as parameter, for example:
This makes every request for a remote resource unique.Code: Select all
mytheme.css?rnd=12345678abcdefg or myscript.min.js?tmp=112358
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
Re: force cache refresh?
Awesome, glad I could help!
Just want to add:
If you are versioning your scripts, you can also reference the version number, for example:
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
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools