Refactor javascript to load partials conditionally