Split javascript code into modules depending on view. Introduce client.js for higher-level access to website data.