Philip Walton came up with a great pattern (and library) to execute JavaScript when the browser is idle, but run it immediately when it is urgent:

Florian Eckerstorfer
@florian
Philip Walton came up with a great pattern (and library) to execute JavaScript when the browser is idle, but run it immediately when it is urgent: