A simplified, JavaScript-based implementation of the famous compression algorithm for illustrative purposes.
LZW is at the heart of zip, png, and many other compression formats. It creates variable-length codes without knowing a probability distribution over symbols beforehand. LZW adapts to the respective data to encode (compress) and manages to be efficient and general purpose at the same time.
A detailed explanation can be found in Mark Nelson's blog posts from 1989 and 2011. For more background on the topic of source coding in general, check out MIT's Digital Communication Systems