Refact javascript into multiple files