Fix race condition in JS load