title: Only running javascript required for current page, best methods?
body: <p>So I know it's best to have one javascript file for an entire site to limit http requests. So obviously only some javascript is required for some pages. <strong>What is the best way of only running the javascript required for the current page?</strong></p>
  
  <p>EG.</p>
  
  <pre><code>if(page=='home'){
    //run javascript require for the home page
  }
  </code></pre>
  
  <p>Maybe this isn't an issue and if targeting elements are not found on the page javascript will just fail gracefully? I would just like to know the best practice for this javascript structure.</p>