by goto11 · 7y ago · 0 comments
You can peruse Can I Use https://caniuse.com/#search=fetch to evaluate if the API is widely enough supported to be viable. Then you have to figure out which bugs and incompatibilities exist across browsers.
If you look at http://youmightnotneedjquery.com/ you will notice that the native approach is at best similar to jQuery, but in many cases more cumbersome and verbose.
30kb is completely insignificant.
Using jQuery is just easier and less risk.
Also, if you're serving jQuery from one of the major CDNs (as many, perhaps most, sites do), the probability that it's already in the browser's cache is pretty close to 1, in which case the "30kb overhead" is utterly irrelevant.
> There is more to it than "wanting to learn".
Indeed. What about people who just think the new official APIs suck?
Strange as it may seem, there are people who would rather type "$" than "document.querySelector", especially when they're going to be doing it hundreds of times. With respect to "bloat", "$" is one character. "document.querySelector" is 22.
And by correctly using polyfills only on browsers that don't support native fetch, the majority of your users (chrome/safari/firefox) won't have any extra dependencies by using fetch, whereas jQuery will need to be loaded on every browser that hits your site.
[1] https://bundlephobia.com/result?p=unfetch@4.1.0 [2] https://bundlephobia.com/result?p=jquery@3.4.1 [3] https://www.telerik.com/blogs/jquery-using-only-what-you-nee...
Does the size of jQuery really matter for a typical web site? If you have just a typical size logo, it will dwarf the size of jQuery, never mind if you have some illustrations or photos.
JavaScript has, in a addition to download time, parse and execution time. These are non-negligible on lower end devices.
30k of JS has a far greater impact on the speed of your page than 30k of images.
In modern sites if javascript doesn't load sites then become non functional, e.g. navs don't work, some SPAs won't work at all. Whereas an image or favicon taking a long time to load shouldn't stop the user from being able to functionally view most of the site.
The point is to not send data the user doesn't need. It doesn't matter if you're using 50MB of images, fonts, video, etc in a page... Adding an extra 30kb you don't need is not good for the user. So don't.
(Also don't stick 50MB of assets in a page please.)