Refactor loading of Javascript libraries