JSFiddle - React, Tailwind, and code Playground

by J. Jones

JavaScript

/* set a max iteration (anything over 10000 here will cause erratic browser behavior) */
var max = 2000;

/* first remove anything we have already used */
for (var y=0; y<max; y++) {
    localStorage.removeItem('key-'+y, 'random-string-'+y);
}

/* current storage size minus 5mb */
document.write('Current storage size minus 5mb<br/>');
document.write(1024 * 1024 * 5 - unescape(encodeURIComponent(JSON.stringify(localStorage))).length);
document.write('<br/>');

/* fill up the localStorage with random key/values */
for (var y=0; y<max; y++) {
    try {
        localStorage.setItem('key-'+y, 'random-string-'+y);
    } catch (e) {
        /* not sure if this works as I have only found one reference to it (chrome doesn't like it) */
        /* http://paperkilledrock.com/2010/05/html5-localstorage-part-one/ */            
        if (e == QUOTA_EXCEEDED_ERR) {
            document.write('Quota exceeded<br/>');
        }
    }
}

/* this should be different now */
document.write('Current storage size after 10000 iterations of random data added<br/>');
document.write(1024 * 1024 * 5 - unescape(encodeURIComponent(JSON.stringify(localStorage))).length);
document.write('<br/>');