optimize the js construction