Encoding Data inside of a URL Query String

Handing over a ticket
Photo by Ben White on Unsplash

Design Goals

First Attempts

A screenshot showing this method failing to encode the string “the rain in spain lands mainly in the plains”. parseInt return NaN which is then converted to “NaN” by toString()
A screenshot showing code that converts a string to its corresponding ASCII codes and then transforms those codes into hexadecimal. In this instance, the result is two times longer than the original string.
this seems counterproductive…

lz-string and Lempel–Ziv–Welch Compression

Lempel–Ziv–Welch (LZW) is a universal lossless data compression algorithm created by Abraham Lempel, Jacob Ziv, and Terry Welch. It was published by Welch in 1984 as an improved implementation of the LZ78 algorithm published by Lempel and Ziv in 1978. The algorithm is simple to implement and has the potential for very high throughput in hardware implementations.[1] It is the algorithm of the widely used Unix file compression utility compress and is used in the GIF image format.

lz-string simplifies everything down to a single function: compressToEncodedURIComponent()
Quick and easy decompression thanks to lz-string
Some additional logic to map the notation to Noodlr’s grid, as well as a redirect in case the query string does not contain valid data

Shareable Vamps: Now at your Fingertips!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Garrett Bodley

Full Stack web developer. Former Creative. Amateur baker, barista, and cat dad. he/him