-
-
Save renodesper/1d41e72ce1dfa9c9e251723b64d9245c to your computer and use it in GitHub Desktop.
Detects the size of the browser's localStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (localStorage && !localStorage.getItem('size')) { | |
var i = 0; | |
try { | |
// Test up to 10 MB | |
for (i = 100; i <= 10000; i += 100) { | |
localStorage.setItem('test', new Array((i * 1024) + 1).join('a')); | |
} | |
} catch (e) { | |
localStorage.removeItem('test'); | |
localStorage.setItem('size', i - 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment