Page 1 of 1

Clear the browser cache

Posted: Mon Sep 17, 2018 4:55 am
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

Re: Clear the browser cache

Posted: Mon Sep 17, 2018 11:35 am
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.

Re: Clear the browser cache

Posted: Mon Sep 17, 2018 2:05 pm
by Jose Manuel
Thank you very much Scott

Re: Clear the browser cache

Posted: Tue Sep 18, 2018 7:45 pm
by Jose Manuel
Okay. it works very well, but does not make the image always download?
It would not affect the performance ??
Thank you

Re: Clear the browser cache

Posted: Tue Sep 18, 2018 7:51 pm
by Scott Klement
It does make this image always download. (But does not affect everything else.)

Re: Clear the browser cache

Posted: Thu Feb 14, 2019 12:47 pm
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));

Re: Clear the browser cache

Posted: Thu Feb 14, 2019 1:05 pm
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?

Re: Clear the browser cache

Posted: Thu Feb 14, 2019 1:54 pm
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?

Re: Clear the browser cache

Posted: Thu Feb 14, 2019 2:05 pm
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.

Re: Clear the browser cache

Posted: Thu Feb 14, 2019 3:53 pm
by mwalter
Thanks for the conformation.