move js to be first in function