title: JS File Not Loading When URL is Directory
body: <p>I wrote a simple 404 page for my website that tells you a joke every time it is loaded. I am accomplishing this with the use of the StackExhange API and am drawing questions off of <a href="https://stackoverflow.com/questions/234075/what-is-your-best-programmer-joke">this thread</a>.</p>
  
  <p>Everything works as intended when I purposely trigger the 404 page with a garbage file url. For example when I go to <code>www.domain.com/garbage</code>, the 404 page loads as expected. My <code>404.shtml</code> has a <code>script</code> tag that loads a <code>404.js</code> script that I wrote and everything is great. </p>
  
  <p>However, when I attempt to get a 404 page by routing to a garbage <em>directory</em> as apposed to a garbage <em>file</em>, the script cannot be found. For example, <code>www.domain.com/garbage/</code> does <strong>NOT</strong> load the <code>404.js</code> script despite the correct <code>404.shtml</code> page being loaded.</p>
  
  <p>Here is the <code>head</code> section of my HTML file.</p>
  
  <pre><code>&lt;head&gt;
      &lt;script src="http://code.jquery.com/jquery-latest.min.js"
              type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="404.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p><strong>Note</strong>: The external jQuery script is loaded <strong>both</strong> times, but <code>404.js</code> is only loaded for the <strong>first</strong> request example.</p>
  
  <p>Here is the console for both requests, the first one is the request for a garbage file and the second is the request for a garbage directory.</p>
  
  <p><strong>First URL:</strong> www.domain.com/garbage<br>
  <code>// a long JSON response from the StackExhange API that indicates that the script loaded</code></p>
  
  <p><strong>Second URL:</strong> www.domain.com/garbage/<br>
  <code>[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (404.js, line 0)</code></p>
  
  <p><strong>Question</strong> What is causing the <code>404.js</code> script to not be loaded when I attempt to access an invalid directory within my site when the same script loads when I attempt to access an invalid file?</p>
  
  <p><strong>What I Have Tried</strong><br></p>
  
  <ul>
  <li>A plethora of Google searches.
  <li>Triple check that all script tags are pointing to the correct files
  </ul>
  
  <p>Thank you for your time. If you wish to do some more digging, you can see the actual problem in action at <code>briantracy.xyz/garbage</code> and <code>briantracy.xyz/garbage/</code>.</p>