moving the js dynamic loading to the function