javascript - How much space does the localstorage key itself take up? -
lets create localstorage key , give empty string. name of keyitem take same amount of space value per character?
for instance does
localstorage.setitem("keyitem","") //equal space of other 1 under? localstorage.setitem("key","item");
also, amount of keys matter? instance
localstorage.setitem("key",""); //equal amount of storage 3 under combined? localstorage.setitem("k",""); localstorage.setitem("o",""); localstorage.setitem("h","");
i found function once calculate size of localstorage
, sessionstorage
objects, can't remember found it.
here's code:
storage.prototype.size = function(units) { 'use strict'; units = units ? units.touppercase() : 'mb'; var size = unescape(encodeuricomponent(json.stringify(this))).length; switch (units) { case 'b': return [size,'b'].join(' '); case 'kb': return [+(size / 1024).tofixed(3),'kb'].join(' '); default: return [+(size / 1024 / 1024).tofixed(3),'mb'].join(' '); } };
i decided go ahead , run tests in various browsers.
firefox (37.0.2):
chrome (42.0.2311.90 m):
ie 11 (11.0.9600.17420):
opera (29.0.1795.47):
so looks firefox, chrome, , opera (probably safari well, don't have that) have same behavior, , keys take far more space values.
in ie (good old ie...), implementation executed in way such doesn't matter how store something.
Comments
Post a Comment