Page 1 of 2

is there an effective way to clear the cache?

Posted: Sun Jun 27, 2021 2:05 am
by skinkairewalker
I made a web menu for a customer, he always asks me to make changes to the menu, and every time I update it's a huge problem, because we can't make restaurant customers "know how to clear the browser cache, because most are technology laymen " , is there an effective way to prevent the cache from getting in the way of page refresh done in SB ?

Re: is there an effective way to clear the cache?

Posted: Sun Jun 27, 2021 9:33 am
by Dirk Geppert
There are many browsers out there, with different ways to clear the cache.
Perhaps it is better not to cache certain files or to keep giving them new names during deployment. For example, with a timestamp...
Just as an idea...

Re: is there an effective way to clear the cache?

Posted: Sun Jun 27, 2021 3:52 pm
by KianV
I don't know if it would be suitable for your application, but inserting:

Code: Select all

!window.location.reload(true);
should force a reload, ignoring the cache.

Re: is there an effective way to clear the cache?

Posted: Sun Jun 27, 2021 8:15 pm
by skinkairewalker
KianV wrote: Sun Jun 27, 2021 3:52 pm I don't know if it would be suitable for your application, but inserting:

Code: Select all

!window.location.reload(true);
should force a reload, ignoring the cache.
how can i use this ? when I try to use it, the page keeps reloading infinitely, is there a way to stop this command from running?
Dirk Geppert wrote: Sun Jun 27, 2021 9:33 am There are many browsers out there, with different ways to clear the cache.
Perhaps it is better not to cache certain files or to keep giving them new names during deployment. For example, with a timestamp...
Just as an idea...
I've tried it, but it didn't work :c

Re: is there an effective way to clear the cache?

Posted: Mon Jun 28, 2021 4:00 am
by KianV
skinkairewalker wrote: Sun Jun 27, 2021 8:15 pm how can i use this ? when I try to use it, the page keeps reloading infinitely, is there a way to stop this command from running?
It needs to be triggered by an Event in the program. This could be clicking on something or when any graphics are finished loading &c..
When this should happen depends very much on the program itself, and when it would be most appropriate.

Re: is there an effective way to clear the cache?

Posted: Thu Jul 01, 2021 1:07 pm
by skinkairewalker
KianV wrote: Mon Jun 28, 2021 4:00 am It needs to be triggered by an Event in the program. This could be clicking on something or when any graphics are finished loading &c..
When this should happen depends very much on the program itself, and when it would be most appropriate.
do u have some code example ?

Re: is there an effective way to clear the cache?

Posted: Thu Jul 01, 2021 5:15 pm
by KianV
Without seeing exactly what your code does, it is difficult to say, but the following should work under all circumstances.

Code: Select all

OpenWindow(0, 100, 100, 320, 200, "Window 0")
TextGadget(0, 10,  70, 300, 20, "This is just to put something on the screen", #PB_Text_Center )

ismenuupdated.s=""
!var v_ismenuupdated = sessionStorage.getItem("pageupdated"); 
;retrieve value from sessionStorage
If ismenuupdated="True"
  Debug "it is already updated"
Else
  Debug "updating the page now"; if value retrieved is not 'True", reload window ignoring cache
  !window.location.reload(true);
  !sessionStorage.setItem("pageupdated", "True");
  ;set value in sessionStorage To 'True'
EndIf

; Put the rest of your code here

Procedure CloseWindowEvent()
  Debug "Closing window: " + EventWindow()
  CloseWindow(EventWindow()) ; Close the specific window
EndProcedure

BindEvent(#PB_Event_CloseWindow, @CloseWindowEvent())
This stores a value in sessionStorage to show that the reload has been done.
The value is stored as long as the window/tab is open. Therefore, when someone comes back to the page again, the value will be lost and the reload will be performed.
I suspect that many people keep the browser on their phones open nearly permanently, so I would suggest putting something at the end - when changing page or checkout or somesuch - to clear the value, just in case.
e.g. !sessionStorage.setItem("pageupdated", "False");

Re: is there an effective way to clear the cache?

Posted: Mon Jul 05, 2021 9:14 am
by Stefan
The problem ist, that "!window.location.reload(true);" not really good works.

Re: is there an effective way to clear the cache?

Posted: Mon Dec 13, 2021 10:22 pm
by William Van Hoecke
skinkairewalker wrote: Sun Jun 27, 2021 2:05 am I made a web menu for a customer, he always asks me to make changes to the menu, and every time I update it's a huge problem, because we can't make restaurant customers "know how to clear the browser cache, because most are technology laymen " , is there an effective way to prevent the cache from getting in the way of page refresh done in SB ?
Same problem here...
!window.location.reload(true); does not clear the cache it always reloads the same old page !

did you find a solution ?

Re: is there an effective way to clear the cache?

Posted: Tue Dec 14, 2021 10:18 am
by Peter
It is not enough to reload the HTML page. You must also ensure that the JavaScript is loaded without cache.

If you look at the HTML page generated by SpiderBasic, you will see the following line:

Code: Select all

<script type="text/javascript" src="spiderbasic.js"></script>
(spiderbasic.js can also have a different name, depending on what you have called your app)

This file must be reloaded bypassing the cash. If the SpiderBasic compiler appended a timestamp to the JavaScript file each time it generated the HTML file, this wouldn't be a problem.

I asked Fred in 2017 to build this into SpiderBasic; unfortunately without success until today: Attach a timestamp to the generated JavaScript