存储本地存储.jpg文件 [英] Storing .jpg files in local storage

查看:122
本文介绍了存储本地存储.jpg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法,从我的网站.jpg文件存储到localStorage的,以增加网站的速度。
其理论简单:picture.jpg转换成一个base64字符串,并将它。用setItem到localStorage的存储。再次显示图片只加载从localStorage的和去code回JPG以base64字符串。但是,一如既往的做法是比较困难的。我试着去找到一种方式可以将.jpg文件转换上即时使用HTML5或JavaScript的base64(没有PHP的!)。是否有人有同样的问题,并能够找到一个解决方案,并能共享code?

I am trying to find a way to store .jpg files from my website into the localstorage to increase the site speed. Theoretical its simple: convert the picture.jpg into a base64 string and store it with setitem into the localstorage. to display the picture again just load the base64 string from the localstorage and decode back to jpg. But, as always, the practice is more difficult. Im trying to find a way to convert the .jpg files on-the-fly to base64 using html5 or javascript (no php!). Does someone had the same problem and was able to find a solution and could share the code?

推荐答案

我也为使用HTML5缓存清单,它支持在离线案例太,是专为您的问题。不要使用本地存储使用Base64因为:

I'm also for using HTML5 cache manifest which supports the offline case too and is designed for your problem. Don't use local storage with base64 because:


  • Base64编码会增加文件大小至137%(!)

  • 的算法将您的应用程序变慢,因为不仅上网速度的限制您的应用程序,也的JavaScript不能以最快的速度在台式计算机上执行。在我的手机类手机测试中,我曾与JavaScript的共同问题,所以我会的JavaScript减少到最低限度,不需要您的上下文。

  • 本地存储不支持evertime并且也限制!

有关高速缓存证明联你可以看一下 w3.org - 缓存舱单还对 HTML5岩有一个初学者指南。

For Cache Manifests you can look to w3.org - Cache Manifests also on html5 Rocks there is a beginner guide.

如果你不想使用HTML5 chache清单,应尽量提高速度尽可能地,这里在计算器很多帖子所描述的,我喜欢的链接的the presentation 有关增加Math对象

If you do not want to use HTML5 chache manifest, you should try to increase the speed as much as possible, described in many posts here on stackoverflow, i liked the link to the presentation in the post about increasing Math Object

这篇关于存储本地存储.jpg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆