improve the javascript loading function