How can I use localStorage for storing .woff and .ttf files ? I don't want to use application cache. Help me. Thanks
Asked
Active
Viewed 2,131 times
4
-
1http://stackoverflow.com/questions/4940586/can-you-use-html5-local-storage-to-store-a-file-if-not-how – bugwheels94 Jul 23 '12 at 10:45
-
3Why don't you want to use the application cache? It's designed for this sort of thing. – robertc Jul 23 '12 at 10:45
-
@robertc :That means localStorage can't be used for this? – radhe001 Jul 23 '12 at 10:57
-
No, but when you don't want to use the primary technology for doing a thing to do that thing, then most people are going to assume that you don't know what you're doing unless you can explain why. – robertc Jul 23 '12 at 12:42
-
local Storage reduces communication between server and client .Using localStorage I want to achieve this and also storage memory is not a problem for me (5 MB is enough).Also I'm more confident in using localStorage than in appCache . – radhe001 Jul 23 '12 at 13:02
2 Answers
1
localStorage is designed to store text key/value pairs, so if you want to save binary data you probably need to base64 encode the data. The size of the encoded binary data will be greater than the orginal size and the localStorage size is limited to a few MB (tipycally 5-10M). Probably it is not a good idea to save the font files in the localStorage.
Disk space for storage: http://dev.w3.org/html5/webstorage/#disk-space
Test localStorga limits: http://arty.name/localstorage.html

user1498339
- 629
- 4
- 9
0
You can store fonts in base64 data .
localStorage.font1 = string(base64 data of specified font)

user1557145
- 24
- 1