optimize javascript into backend