9

I'm building a mobile web app that will rely on caching. If my cache uses to much memory I'm seeing this message in mobile Safari...

"A problem occurred with this webpage so it was reloaded".

Without intervention the page will reload and do the same thing over again a few times until it gives up.

Are there events I can capture, heap information I can monitor or settings that I can change to build a caching system that is more resilient than forcing page reloads?

Chrome has window.performace.memory but I can't seem to find anything related to solving my issue in mobile Safari. Try/catch statements and onBeforeUnload events don't prevent the page loads or provide an opportunity to clear/reduce the cache.

Tyler Larson
  • 261
  • 3
  • 4

1 Answers1

1

Does this help ?

Error handling "Out of Memory Exception" in browser?

var localStorageSpace = function(){
var allStrings = '';
for(var key in window.localStorage){
    if(window.localStorage.hasOwnProperty(key)){
        allStrings += window.localStorage[key];
    }
}
return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';
};

var storageIsFull = function () {
var size = localStorageSpace(); // old size

// try to add data
var er;
try {
     window.localStorage.setItem("test-size", "1");
} catch(er) {}

// check if data added
var isFull = (size === localStorageSpace());
window.localStorage.removeItem("test-size");

return isFull;

}

Community
  • 1
  • 1
Basit Anwer
  • 6,742
  • 7
  • 45
  • 88
  • I'm not using localStorage, but your proposed system relies on knowing the memory limitations of this feature, I don't know how much memory there is available which is the heart of the problem. – Tyler Larson Jun 10 '16 at 15:11
  • 1
    Another helpfull link. http://stackoverflow.com/questions/23506064/how-do-you-detect-memory-limits-in-javascript – Basit Anwer Jun 10 '16 at 15:55