DEV Community

Discussion on: Do you still work with jQuery?

anilseervi profile image
Anil Seervi

Top level awaits tho

Thread Thread
link2twenty profile image
Andrew Bone • Edited on

Helper functions can also be a thing.

const getJSON = async (url, callback) => {
  const response = await fetch(url);
  const data = await response.json();

getJSON("/my/url", console.log);
Enter fullscreen mode Exit fullscreen mode
Thread Thread
nataliedeweerd profile image
𝐍𝐚𝐭𝐚𝐥𝐢𝐞 𝐝𝐞 𝐖𝐞𝐞𝐫𝐝

I understand where you're coming from, but for modern Internet speeds 30kb is nothing. Sure, it's worth taking into account if you're launching a site for a territory which suffers from slow Internet speeds, but for most affluent countries I'd argue 30kb is not worth losing sleep over.

In the UK the average Internet speed in 2015 was 13 MBps. It really takes no time at all to download such a tiny file.

Thread Thread
lukeshiru profile image
Luke Shiru

You have to consider mobile networks as well, which can be very fast, but if you're far enough of phone antennas or isolated (maybe on an old house, or a subway station or whatever), then those 30k are a lot just to achieve the same thing you'll get from using fetch. Ideally we should always avoid downloading unnecessary JS. Just take a look at the trends that Remix or Astro are imposing, where JS is loaded only if needed, if not we just use HTML+CSS and that's ok.