Relative paths with fetch in Javascript

When you say fetch('data.json') you are effectively requesting http://yourdomain.com/data.json since it is relative to the page you’re are making the request from. You should lead with forward slash, which will indicate that the path is relative to the domain root: fetch('/js/data.json'). Or fully qualify with your domain fetch('http://yourdomain.com/js/data.json').

Leave a Comment