首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >存储脱机web应用程序的图像数据(客户端存储数据库)

存储脱机web应用程序的图像数据(客户端存储数据库)
EN

Stack Overflow用户
提问于 2013-01-02 02:56:53
回答 4查看 36.9K关注 0票数 111

我有一个使用appcaching的离线web应用程序。我需要提供它大约10MB - 20MB的数据,它将保存(客户端)主要由PNG图像文件组成。具体操作如下:

从服务器PNG数据文件中下载和安装

  1. 网络应用程序(使用清单)
  2. 网络应用程序请求(方式?-查看替代方案
  3. 网络应用程序与服务器重新同步,并对PNG数据库进行小的部分更新/删除/添加
  4. 仅供参考:服务器是一台JSON REST服务器,可以将文件放置在wwwroot中以便拾取

下面是我目前对处理二进制blob存储的基于客户端的“数据库”的分析

请参阅底部的更新

  • AppCache (通过清单添加所有PNG,然后按需更新)

代码语言:javascript
复制
- CON: any change of a PNG database item will mean complete download of all items in manifest (Really bad news!)

  • WebStorage

代码语言:javascript
复制
- CON: Designed for JSON storage
- CON: can only store blobs via base64 encoding (probably fatal flaw due to cost of de-encoding)
- CON: Hard limit of 5MB for webStorage [http://htmlui.com/blog/2011-08-23-5-obscure-facts-about-html5-localstorage.html](http://htmlui.com/blog/2011-08-23-5-obscure-facts-about-html5-localstorage.html)

  • PhoneGap和SQLLite

代码语言:javascript
复制
- CON: Sponsor will reject it as a native app requiring certification

  • ZIP file

代码语言:javascript
复制
- Server creates a zip file, places it in wwwroot, and notifies client
- user has to manually unzip (At least that is how I see it) and save to client file system
- Web app uses FileSystem API to reference files
- CON: ZIP might be too large (zip64?), long time to create
- CON: Not sure if FileSystem API can always read out of the sandbox (I think so)

  • USB或SD卡(回到石器时代...)

代码语言:javascript
复制
- The user will be local to the server before going offline
- So we could have him insert a SD card, let the server fill it with PNG files
- Then the user will plug it into the laptop, tablet
- Web app will use FileSystem API to read the files
- CON: Not sure if FileSystem API can always read out of the sandbox (I think so)

  • WebSQL

代码语言:javascript
复制
- CON: w3c has abandoned it (pretty bad)
- I might consider a Javascript wrapper that uses IndexedDB and WebSQL as a fall-back

  • FileSystem API

代码语言:javascript
复制
- Chrome supports read/write of blobs
- CON: not clear about IE and FireFox (IE10, has non-standard msSave)
- caniuse.com reports IOS and Android support (but again, is this just r/w of JSON, or does it include the full blob API for writing?
- CON: FireFox folks dislike FileSystem API & not clear if they are supporting saving blobs: [https://hacks.mozilla.org/2012/07/why-no-filesystem-api-in-firefox/](https://hacks.mozilla.org/2012/07/why-no-filesystem-api-in-firefox/)
- PRO: _Much_ faster than IndexedDB for blobs according to jsperf [http://jsperf.com/indexeddb-vs-localstorage/15](http://jsperf.com/indexeddb-vs-localstorage/15) (page 2)

  • IndexedDB

代码语言:javascript
复制
- Good support in IE10, FireFox (save, read blobs)
- Good speed and easier management than a file system (deletes, updates)
- PRO: see speed tests: [http://jsperf.com/indexeddb-vs-localstorage/15](http://jsperf.com/indexeddb-vs-localstorage/15)
- See this article on storing and display of images in IndexedDB: [https://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/](https://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/)
- CON: I confirmed that Chrome does not yet support blob writing (current bug, but not clear when it will be fixed)
- UPDATE: [A June 2014 blogpost](https://developers.google.com/web/updates/2014/07/Blob-support-for-IndexedDB-landed-on-Chrome-Dev) suggests Chrome now supports blobs in `IndexedDB`
- UPDATE: [This caniuse/indexeddb](https://caniuse.com/#search=indexeddb) confirms: "Chrome 36 and below did not support Blob objects as indexedDB values."; suggesting >Chrome36 supports Blob objects.

代码语言:javascript
复制
- PRO: very clean wrapper for IndexedDB, WebSQL or whatever database you have (think polyfill)
- CON: cannot store binary blobs, only data:uri (base64 encoding) (probably fatal flaw due to cost of de-encoding)

polyFill JQUERY

代码语言:javascript
复制
- Parashuram has writtent a nice JQUERY wrapper for the raw IndexedDB interface
- PRO: greatly simplifies using IndexedDB, I was hoping to add a shim/polyfill for Chrome FileSystemAPI
- CON: It should handle blobs, but I was unable to get it to work

代码语言:javascript
复制
- Eric Bidelman @ Google has written a well tested PolyFill the FileSystem API that uses Indexed DB as a fall back
- PRO: FileSystem API is well suited for storing blobs
- PRO: works great on FireFox and Chrome 
    - PRO: great for synchronizing with cloud based CouchDB
代码语言:javascript
复制
- CON: no clear why, but it is not working on IE10

代码语言:javascript
复制
- great for syncing a CouchDB with a local DB (uses either WebSQL or IndexedDB (not my problem though)
- CON: NO CONS, PouchDB now supports binary blobs for all recent browsers (IE, Chrome, Firefox, Chrome on mobile, etc.) as well as many older browsers. That was not the case when I first did this post.

注意:为了查看PNG的data:uri编码,我在http://jsbin.com/ivefak/1/edit上创建了一个示例。

所需的功能(/u)

  • 客户端上没有本机(EXE,PhoneGap,ObjectiveC等)应用程序(纯网页application)
  • Only需要运行在最新的Chrome,FireFox,IE10为laptops
  • Strongly想要相同的解决方案为安卓平板电脑(IOS会很好),但只需要一个浏览器工作(FF,铬等)
  • 快速初始DB
  • 从存储(数据库,文件)
  • 非常快的图像检索从存储(数据库,文件)不意味着消费者。我们可以限制浏览器,并要求用户执行特殊设置和任务,但让我们最小化

IndexedDB Implementations

SQL database

  • In short:
  • IE使用与http://www.aaron-powell.com/web/indexeddb-storage
  • In相同的数据库格式,而IndexedDB
  • Firefox的Active
  • 使用的是,因此我们在SQL IndexedDB
    • Firefox(和WebKit)中实现了一个NoSQL数据库使用的是具有BigTable

传统的键/值存储

My Current Results

  • 我选择使用IndexedDB方法(在他们发布blob support)
  • For fetching磁贴之前,使用IndexedDB的FileSystemAPI填充Chrome ),我有一个两难的选择,因为JQUERY的人很想把这个添加到AJAX
  • 中。我选择了Phil Parson的XHR2-Lib,它非常类似于100MB下载的JQUERY .ajax() IE10() FireFox ()
  • 我不能让任何indexeddb包装器工作于blob(草椅,PouchDB,jquery-indexeddb等)。
  • 我滚动了自己的包装器,和性能是(SQL2s、Chrome3s、FireFox 10s)和带FF的
  • ,我假设我们看到了针对非sqllite使用关系数据库(sqllite)的性能问题Chrome具有用于检查sqllite状态的出色调试工具(开发人员选项卡、资源

最终结果发布在下面作为answer

更新

PouchDB现在支持所有最新浏览器(IE、Chrome、Firefox、移动上的Chrome等)的二进制blob。以及许多较老的浏览器。当我第一次写这篇文章时,情况并非如此。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-01-24 01:14:05

PNG滑动贴图的脱机blob缓存结果

测试

Chrome

  • 171 PNG文件(测试的3.2MB)

  • Platforms总数: Chrome v24、FireFox 18、IE 10

  • 也应适用于适用于的Chrome& FF

从web服务器获取

  • 使用XHR2 (几乎所有浏览器都支持)从web服务器下载blob我选择了Phil Parson的XHR2-Lib,它非常类似于JQUERY .ajax()

存储

适用于IE和FireFox

  • Chrome: Polyfill的
  • IndexedDB (使用FileSystem API存储blob,引用保存在IndexedDB中) polyfill
  • A必须阅读有关"How
    • IndexedDB IndexedDB data“的文章

stored separately)

  • Note: Microsoft IE使用可扩展存储引擎:blobs

显示

  • 我正在使用Leaflet http://leafletjs.com/显示地图切片
  • 我使用了Ishmael Smyrnow的功能切片图层插件从DB Leaflet中获取切片图层

我将基于DB的tiles层与纯本地( storage

  • There ://)tiles进行了比较,
  • 在性能上没有明显的区别!在使用IndexedDB和本地files!

之间

结果

  • Chrome:读取(6.551s),存储(8.247s),总运行时间:(13.714s)
  • FireFox:读取(0.422s),存储(31.519s),总运行时间:(32.836s)
  • IE 10:读取(0.668s),存储:(0.896s),总运行时间:(3.758s)
票数 26
EN

Stack Overflow用户

发布于 2013-01-02 05:38:13

对于您的需求,我建议基于另外两种填充方式开发一种新的填充方式:和IndexedDB to WebSQL -是最好的选择。

前者将支持在Chrome (FileSystem API)和Firefox (IndexedDB)中存储blobs,而后者应该支持Android和iOS (WebSQL)。我们需要做的就是让这些多层填充一起工作,我想这并不难。

NB:因为我在网上找不到任何关于这方面的信息,你应该测试一下使用WebSQL polyfill存储斑点是否可以在iOS和安卓上工作。不过,看起来它应该可以工作:

代码语言:javascript
复制
var sql = ["CREATE TABLE", idbModules.util.quote(storeName), "(key BLOB", createOptions.autoIncrement ? ", inc INTEGER PRIMARY KEY AUTOINCREMENT" : "PRIMARY KEY", ", value BLOB)"].join(" ")

Source

票数 4
EN

Stack Overflow用户

发布于 2013-05-24 17:16:46

我有地图缓存examples(打开示例,发现区域和缩放,切换离线和发现的区域将可用)。

有用于离线磁贴的map.js - map层,基于IndexedDb和WebSQL的storage.js - storage实现(但这只是测试实现,性能很差)。

站点文件(html、css、js等)的

  • 我更喜欢使用应用程序缓存。
  • 用于存储我更喜欢使用索引DB (支持blob),Web (只支持base64),FileWriter (支持blob,但只支持chrome)。坦率地说,存储是这方面的一个大问题。您需要最快的key value解决方案,将它们混合在一起。我认为使用exist解决方案是个不错的决定。
  • 用于抓取时,我使用了带有CORS的canvas。但我想到了WebWorkers和XHR2,这可能会比canvas更好,因为canvas在不同的浏览器和其他浏览器中使用CORS时会遇到一些问题(例如,this title被存储为canvas

有关20亿城市(Minsk)规模的其他信息:

  • 缩放- 9,平铺- 2,大小- 52 kb,上一个- 52 kb;
  • 缩放- 10,平铺- 3,大小- 72 kb,上一个- 124 kb;
  • 缩放- 11,平铺- 7,大小- 204 kb,上一个- 328 kb;
  • 缩放- 12,平铺- 17,大小- 348 kb,上一个-676kb;
  • 缩放- 13,平铺- 48,大小- 820 kb,上一个-1.5kb;
  • 缩放- 14,平铺- 158,大小- 2.2 mb,上一版本- 3.7 mb;
  • 缩放- 15,平铺- 586,大小- 5.5 mb,上一版本- 9.3 mb;
  • 缩放- 16,平铺- 2264,大小- 15 mb,上一版本-24.3mb;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14113278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档