Skip to content

Instantly share code, notes, and snippets.

@lowlevel-1989
Forked from cdmckay/local-storage-size.js
Last active August 29, 2015 14:27
Show Gist options
  • Save lowlevel-1989/9e6fc7aa2c8a81765a3b to your computer and use it in GitHub Desktop.
Save lowlevel-1989/9e6fc7aa2c8a81765a3b to your computer and use it in GitHub Desktop.
Detects the size of the browser's localStorage
if (localStorage && !localStorage.getItem('size')) {
var i = 0;
try {
// Test up to 10 MB
for (i = 250; i <= 10000; i += 250) {
localStorage.setItem('test', new Array((i * 1024) + 1).join('a'));
}
} catch (e) {
localStorage.removeItem('test');
localStorage.setItem('size', i - 250);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment