Optimize js code