网页 LocalStorage 存储知多少

2018/07/04 Web

网页缓存容量测试 localstorage

LocalStorage 容量测试

测试代码

(function () {
    if (!window.localStorage) {
        console.log('当前浏览器不支持localStorage!')
    }
    var test = '0123456789';
    var add = function (num) {
        num += num;
        if (num.length == 10240) {
            test = num;
            return;
        }
        add(num);
    }
    add(test);
    var sum = test;
    var show = setInterval(function () {
        sum += test;
        try {
            window.localStorage.removeItem('test');
            window.localStorage.setItem('test', sum);
            console.log(sum.length / 1024 + 'KB');
        } catch (e) {
            alert(sum.length / 1024 + 'KB超出最大限制');
            clearInterval(show);
        }
    }, 0.1)
})()

各个浏览器支持容量大小

PC

Chrome:5120Kb
QQ浏览器:5120Kb
360浏览器:5120Kb
搜狗浏览器:5120Kb

Mobile

手机QQ内置浏览器:5120Kb
手机微信内置浏览器:5120Kb
搜狗浏览器:510Kb(会崩溃)-> 720Kb
Chrome: 5120Kb

Search

    Table of Contents