Chrome 扩展存储大量数据

Chrome extension store large amounts of data

我正在寻找一种在我的 chrome 扩展程序中存储大量数据的有效方法。我有一些大约 1-2mb 的 txt 文件。 我希望我的 chrome 扩展到本地 'cache' 它们,这样我就不需要每次都获取它们。 我找到了 syncFileSystem,但这仅适用于打包的应用程序。

There were warnings when trying to install this extension:

'syncFileSystem' is only allowed for packaged apps, but this is a extension.

在 chrome 扩展程序中存储此类数据的最佳方式是什么?

manifest.json

{
    "manifest_version": 2,
    "name": "__MSG_name__",
    "version": "1.0",
    "default_locale": "en",
    "description": "__MSG_description__",
    "icons" : {
        "16" : "img/logo_enabled_16.png",
        "48": "img/logo_enabled_48.png",
        "128": "img/logo_enabled_128.png"
    },
    "browser_action": {
        "default_icon": "img/logo_enabled_48.png",
        "default_title": "__MSG_browser_action_title__",
        "default_popup":"options.html"
    },
    "background": {
        "scripts": [
            "js/chrome.js",
            "js/filter.js",
            "js/background.js"
        ],
        "persistent": true
    },
    "content_scripts": [{
        "matches": [
            "http://*/*",
            "https://*/*"
        ],
        "js": [
            "js/docReady.js",
            "js/content.js"
        ]
    }],
    "offline_enabled":true,
    "options_ui": {
        "chrome_style": true,
        "page":"options.html"
    },
    "permissions": [
        "activeTab",
        "tabs",
        "webRequest",
        "webRequestBlocking",
        "webNavigation",
        "storage",
        "syncFileSystem",
        "http://*/*",
        "https://*/*"
    ],
    "short_name": "__MSG_shortName",
    "minimum_chrome_version":"45.0.2454.101",
    "web_accessible_resources":[
        "css/bootstrap.min.css",
        "js/jquery.min.js",
        "js/chrome.js",
        "js/bootstrap.min.js"
    ]
}

WebSQL, IndexedDB, chrome.storage.local and HTML5 File System (sandboxed file system) can grow past 5MB limit via "unlimitedStorage" permission.

manifest.json: "permissions": ["unlimitedStorage"]

Provides an unlimited quota for storing HTML5 client-side data, such as databases and local storage files. Without this permission, the extension or app is limited to 5 MB of local storage.

备注:

  • WebSQL 被 W3C 弃用,取而代之的是较慢的 IndexedDB,但我认为它会保留在 Chrome 中,原因很明显,由于 [=34=,它更快更灵活]-based.
  • chrome.storage.local 是最容易使用的,但对于大型对象可能不是最快的,如果速度很重要,请进行一些测试。
  • 如果收益显着,请使用 Zip/LZMA Javascript 库来 compress/decompress 文本文件。