Improve onload handling for scripts