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:

Idle Until Urgent

Florian Eckerstorfer @florian