Clear the browser cache

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
Jose Manuel
Profound User
Posts: 39
Joined: Mon Aug 21, 2017 11:48 am
First Name: Jose
Last Name: hernandez Guerra
Company Name: CM de gestion y servicios S.L.
Phone: 638489712
Address 1: CL Jose Luis de Cassos 50
City: Sevilla
State / Province: Outside Canada/USA
Zip / Postal Code: 41005
Country: Spain
Contact:

Clear the browser cache

Post by Jose Manuel »

Hello everyone, is there any api in Profoundui that clean the browser cache ??
The case is the following, I upload an image through the widget, that image has a fixed name (EAN code of the article), once the upload is done, I show the image that has been uploaded, but if I want to upload the same reference again name but with another image (for whatever reason) shows me the previous image. That is what is in cache. can be avoided by clearing the browser cache before uploading the image again. But there is not an Api that can do that without the user having to use the History and browser cache cleaners ??
Thank you
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Clear the browser cache

Post by Scott Klement »

It's not possible for an application running in a web browser to clear the browser's cache -- and, even if it were, this would not be a good idea. Clearing the cache would affect every single page that a user visits, not just your program. Even if your user only uses it for Profound UI, it would be an absolute disaster for performance. It is a bad approach.

If the goal is simply to refresh one image, simply change the image URL each time. This technique is often called a "cache buster", and is very common, used by web programmers of all sorts, throughout the world. The same technique works with Profound UI as would work with HTML -- the only difference is that you change a widget property instead of an HTML tag.

For example, if your "image source" property currently looks like this:

Code: Select all

/myimages/image123.jpg
You would change it to look like this:

Code: Select all

script: "/myimages/image123.jpg?r=" + Math.floor(Math.random() * 1000000000);
This keeps the filename the same "image123.jpg" but adds a random number to the end of the URL. Since that random number is different every time, the image is never loaded from the browser's cache.
Jose Manuel
Profound User
Posts: 39
Joined: Mon Aug 21, 2017 11:48 am
First Name: Jose
Last Name: hernandez Guerra
Company Name: CM de gestion y servicios S.L.
Phone: 638489712
Address 1: CL Jose Luis de Cassos 50
City: Sevilla
State / Province: Outside Canada/USA
Zip / Postal Code: 41005
Country: Spain
Contact:

Re: Clear the browser cache

Post by Jose Manuel »

Thank you very much Scott
Jose Manuel
Profound User
Posts: 39
Joined: Mon Aug 21, 2017 11:48 am
First Name: Jose
Last Name: hernandez Guerra
Company Name: CM de gestion y servicios S.L.
Phone: 638489712
Address 1: CL Jose Luis de Cassos 50
City: Sevilla
State / Province: Outside Canada/USA
Zip / Postal Code: 41005
Country: Spain
Contact:

Re: Clear the browser cache

Post by Jose Manuel »

Okay. it works very well, but does not make the image always download?
It would not affect the performance ??
Thank you
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Clear the browser cache

Post by Scott Klement »

It does make this image always download. (But does not affect everything else.)
mwalter
Experienced User
Posts: 140
Joined: Wed Sep 14, 2016 2:58 pm
First Name: Mark
Last Name: Walter
Company Name: Paragon Consulting Services
Contact:

Re: Clear the browser cache

Post by mwalter »

Scott,

Would this also work for loading external javascript?

Right now, I'm loading some external javascript in the window's onload event like this:

Code: Select all

pui.loadJS(pui.normalizeURL("/profoundui/userdata/js/transfers.js"));
pui.loadCSS(pui.normalizeURL("/profoundui/userdata/css/NexusDevice.css"));
could I do something like

Code: Select all

var jsFile = "/profoundui/userdata/js/transfers.js?r=" + Math.floor(Math.random() * 10000000);
pui.loadJS(pui.normalizeURL(jsFile));
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Clear the browser cache

Post by Scott Klement »

Mark, I think that'd work, but I'm not sure. There's a good chance that it'd cause other problems (like memory leaks) but I'm not sure about that, either...

Can you explain why you want to do that? Would using JavaScript's eval() capability be a better solution?
mwalter
Experienced User
Posts: 140
Joined: Wed Sep 14, 2016 2:58 pm
First Name: Mark
Last Name: Walter
Company Name: Paragon Consulting Services
Contact:

Re: Clear the browser cache

Post by mwalter »

We currently have a fleet of Zebra tablets deployed using MobiControl to lock them down. We've been making changes to some external javascript files and have had issues where the tablets aren't getting the most recent code.

Clearing the cache is not an option for the users. They need to be taken out of MobiControl, then cleared by IT, then put back into MobiControl.

Can you be more clear as to what the eval() function will do for me?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Clear the browser cache

Post by Scott Klement »

eval() is used to evaluate JavaScript code at runtime. For example, if you had JS code in a string variable and wanted to run it. It doesn't sound like that's applicable to your situation, though.

I misread the event you were using, I thought you were wanting to replace the JS code as a particular screen was loading. I see now that you want to do it when the browser's window object is loading... that makes more sense. That sounds like it'd work fine.
mwalter
Experienced User
Posts: 140
Joined: Wed Sep 14, 2016 2:58 pm
First Name: Mark
Last Name: Walter
Company Name: Paragon Consulting Services
Contact:

Re: Clear the browser cache

Post by mwalter »

Thanks for the conformation.
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests