

But JavaScript doesn’t have UTF-8 encoding as an option, so whatever we do we have to pretend it’s UTF-16. The obvious answer is to remove those null bytes by changing to UTF-8 encoding. Create a UTF-8 bytestream, and pretend it’s UTF-16 So, if you, like us, are worried about storing more stuff offline, and you want your 25MB back, here are a few options: 1. Every other byte is a null byte and 50MB of storage just became effectively 25MB. Here’s an illustration of how Hello World is stored in UTF-16: 00ĭisaster. When we start encoding English text using UTF-16, and then store it somewhere with limited space, you quickly find you can only store half the number of characters that you thought you’d get. However, English speakers have always been spoiled by the ability to consider memory capacity in bytes to roughly equal the number of characters that can be stored, because English is typically encoded uisng ASCII (exactly one byte per character) or UTF-8 (typically one byte per character with occasional multi-byte characters). This is actually a pretty good choice – it allows JavaScript to be fully Unicode compliant and also makes string operations fast, because counting characters is just a matter of counting bytes. Even characters from basic ASCII get two bytes. Internally, JavaScript encodes text as UTF-16, a simple form of Unicode that allocates two bytes per character. So we need ways of trying to do more with less, and fortunately, there is an obvious place to start.

BASE64 BINARY TO ASCII TEXT ENCODING ENCODED 13 TIMES OFFLINE
If a user wants anything like a reasonable chunk of the FT for offline reading, 50MB is nothing. But the FT publishes hundreds of stories a day, along with more than a hundred high resolution images, not to mention podcasts and videos. You might look at these and think that actually they’re pretty generous – 50MB seems to be the lowest common denominator.

Here’s a table of the restrictions by storage API and browser, which we determined by a combination of reading specs, consulting browser vendors and testing experimentally: A native app can use all the storage it wants, while a web app hits quotas and limits at every turn. Sadly it’s not a fair fight, particularly when it comes to storage. Text re-encoding for optimising storage capacity in the browser
