Repostioning the Script element in head and improving optimization