Help implementing audio dynamic range compression
Here are some suggestions:


There are plenty of opensource implementations (Sox, Audacity, etc). Even if you don't understand them, you might be able to translate the code from C to javascript.
I'm not aware of a good explanation of the process online, but there are plenty of books on the subject:

Digital audio signal processing covers this topic and is well written. (As does DAFX, but DAFX is poorly organized and the coverage is less straightforward)
Digital Audio with Java also covers this topic and comes with working Java code that should be easy to translate to other languages, such as javascript. This book has many many flaws, but it is good for someone with no audio programming experience.



The principle is to create an envelope of the signal (controlled by attack and release), shape that envelope using using some transfer function (controlled by ratio, threshold and knee), and then apply that result back to the original signal. A makeup gain stage often follows.

@Deve's answer suggests some possible transfer functions.