refactor javascript serverside vars usage