Search code examples
firefox-os

How do I force an app to reload when opened


I'm working on a todo app that uses indexedDB. Everything is working fine on my Flame phone. One exception: when I open the app a day later to check my tasks, it doesn't reload the database. Yesterday's items still appear as today's items, etc. I have to hold the home button, quit the app and the start it again. I used the code below to force reloads, but it doesn't seem to work.

<meta http-equiv = "pragma" content = "no-cache">
<meta http-equiv = "cache-control" content = "no-cache">

Solution

  • Use the visibilitychange event to listen when your app becomes active.

    function handleVisibilityChange() {
      if (!document.hidden) {
        // reload
      }
    }
    
    document.addEventListener("visibilitychange", handleVisibilityChange, false);