A quick history of data fetching in JavaScript
codeamigo.dev
codeamigo.dev
var script = document.createElement('script')
script.src = 'http://api.example.com/foo?bar=baz&callback=myFunction'
document.head.appendChild(script)
and then the server would (hopefully) return a JavaScript response, wrapping the JSON in the (global!) function of your choosing: myFunction({...JSON here...})
In addition to the risk of a malicious API server being able to execute whatever code it wanted on your page, this also caused architectural headaches: the callback function had to be on `window` so that the JSONP response would have access to it when it loaded. In addition to the immediately obvious problems with globals, you also had to think very carefully about how to structure things so that the callback knew what it was supposed to do when called. (Woe betide you if some important state could change and the response didn’t have enough context to tell whether it was still relevant.)This is cool. I remember telling someone I was introducing to web app development how they should follow a similar path: Learn XHR, then jQuery Ajax, then fetch/axios for example.
Just so they can see why the newer methodologies exist.
I'm convinced this is one of the best ways of learning (whether you're going for breadth or depth). Knowing the path an ecosystem took and the stops along the way is critical to understanding why things are as they are, and contrasting new entrants.
This comes up a lot in frontend framework fatigue. Most frontend frameworks and tools exist in a path-dependent context and knowing the path often answers many questions.
This is also the reason why a mark of high quality projects is the comparison section ("Why use X over Y?"). It indicates that the creator is a student of the history and intentionally struck out to create something different (and possibly better).
In the old 'require' days this was easy: delete it from the cache and then re-require. But AFAICT there is no equivalent[0] for ES2016 modules, and weirder still, no one seems to miss it or request it as a feature. This is surprising - I'd think people would want to, say, add something to a module and then have a running node application that imports that module pick up the change without restarting the node app.
0: It is possible, but only by doing hacky things to fool the cache in to thinking it's a new file - e.g. make a symlink to the module file and dynamically import the symlink, or for an http import, add an unnecessary parameter to the url.
I work on a number of websites at work. None of them use fetch. They all still use xmlhttprequest whether natively, through jquery, or using a library.
That aside, great UX and story-telling experience for learning!