Modularize profile javascript

@rlucioni @AlasdairSwan Please review.