Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Files opened from disk can run JS. But you can't do <script src="otherfile.js"> without getting a cross-origin error, even if it's in the same directory. So any kind of code organization at all is prohibited.


  ~/scratch/wrong$ cat ./index.html
  <!doctype html>
  <html>
  <head>
  <script src="otherfile.js"></script>
  </head>
  <body>
  <p>otherfile.js did not run</p>
  </body>
  </html>

  ~/scratch/wrong$ cat ./otherfile.js 
  window.onload = (() => {
    document.querySelector("p").textContent = "wrong.  (otherfile.js ran)";
  });




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: