News for hackers. Stuff that matters.
Re:A day without JavaScript by sametmax on Wednesday June 07, 2017 @07:57AM (#14505501)
Yeah. Except you need to do Ajax and fetch doesn't cut it. So new lib. And manipulate the dom with something better then the browser API or you loose your mind. So new lib. Then normalize browser events. Oh wait, you can do that manually. But you are writing a new lib. Eventually the code will grow to be the size of jQuery anyway. Only not as well tested, documented and cached.
Re:A day without JavaScript by nilved on Wednesday June 07, 2017 @08:29AM (#14505729)
> Yeah. Except you need to do Ajax and fetch doesn't cut it. So new lib.

Ah, so this is how front-end got the way it is.

Re:A day without JavaScript by maze-le on Wednesday June 07, 2017 @09:13AM (#14506101)
You can implement an minimal ajax interface in js (no jquery) in less than 30 LOC. But I grasp what you mean, it not just that. There are other concerns and requirements and you do not want to reinvent the wheel everytime...
Re:A day without JavaScript by moron4hire on Wednesday June 07, 2017 @09:46AM (#14506374)
I am so sick and tired of this argument. Having done it several times, no, you do not end up with something as big as jQuery, not by a long shot.
Re:A day without JavaScript by sametmax on Wednesday June 07, 2017 @01:57PM (#14508474)
Sure, if all you do is some onclick() and a few appendChild().

Plus for the time you spend chasing compat issues, writting wrappers, choosing small libs and packing it all together, you could have done your site. For less than 40ko.

People are not blinking at including react ecosysteme, which is huge. But attack jQuery ? Seriously ?

Re:A day without JavaScript by moron4hire on Wednesday June 07, 2017 @02:06PM (#14508541)
> chasing compat issues, writting wrappers, choosing small libs and packing it all together, you could have done your site.

I don't know about you, but usually my projects last longer than a week, so those sorts of savings don't represent a significant chunk of my overall development time. Also, I'm not a shit programmer, so I can actually write a for loop that does what I want on the first try. I've spent more time trying to figure out jQuery's goofy syntax and what the hell it's doing with AJAX queries than it has ever saved me in development.

Re:A day without JavaScript by Udik on Wednesday June 07, 2017 @11:08AM (#14507042)
As big as jQuery? Gzipped it's 27k, a ridiculously small size.
Re:A day without JavaScript by zmodem on Wednesday June 07, 2017 @11:54AM (#14507399)
Ridiculously small? That could take 10 s to download on a 2G network.
Re:A day without JavaScript by sametmax on Wednesday June 07, 2017 @01:55PM (#14508461)
Yeah, sure, most sites today are totally browsable in 2G.

Event the damn native APP for hackernews, using only JSON, is not usable in 2G.

Re:A day without JavaScript by ahakki on Thursday June 08, 2017 @01:03AM (#14512009)
For me HN seems to be one of the few websites that is usable on 2G.
Re:A day without JavaScript by moron4hire on Wednesday June 07, 2017 @12:03PM (#14507473)
Network bandwidth usage is also not the only metric of size we care about. After it's ungzipped, it needs to be parsed by the JS engine, and more code = slower execution.
Re:A day without JavaScript by shakna on Wednesday June 07, 2017 @08:11AM (#14505601)
> Yeah. Except you need to do Ajax and fetch doesn't cut it. So new lib.

Why doesn't fetch and its polyfill cut it?

Re:A day without JavaScript by sametmax on Wednesday June 07, 2017 @08:36AM (#14505782)
Polyfill. So new lib.

And even then. You need to encode params manually.

And of course no middleware, so for special decoding or repeating headers, you end up writting a wrapper.

Re:A day without JavaScript by megous on Wednesday June 07, 2017 @09:23AM (#14506170)
Programming is mostly creating functions and interfaces to decompose problems into reusable parts where reuse makes sense. Nothing wrong with creating a simple function for making XMLHttpRequests or for fetch API. Most of the time there's no need for the level of generality of jQuery interfaces.

Just by making a function you're not creating a library. Sometimes I find DOM API verbose too. Nevertheless the fix does not need to be a interface like jQuery to completely hide DOM API under another interface. It may be enough to extend the HTMLElement prototype a bit or write a function to "compress" the code a bit and make it more readable.

Re:A day without JavaScript by forgottenpass on Wednesday June 07, 2017 @12:04PM (#14507481)
Just by making a function you're not creating a library.

Have you seen what passes for a library on npm?

Re:A day without JavaScript by megous on Wednesday June 07, 2017 @01:48PM (#14508382)
Good point. :D
Re:A day without JavaScript by sametmax on Wednesday June 07, 2017 @01:53PM (#14508433)
> it may be enough to extend the HTMLElement prototype a bit

You lost me here. Anybody extending standard objects cannot be taken seriously.

Re:A day without JavaScript by megous on Wednesday June 07, 2017 @02:41PM (#14508812)
Do you realize JavaScript is a prototype based programming language? It is a major and very useful feature of the language. There's no reason not to use it. There are some things to be careful about with interop if you need it, but that's it.
Re:A day without JavaScript by jamiepenney on Wednesday June 07, 2017 @05:27PM (#14510014)
We've already learned from our past mistakes changing the prototype of the standard library - the Ruby community learned the same thing with monkey patching their standard lib too. The maintenance overhead far outweighs any immediate benefits.
Re:A day without JavaScript by megous on Wednesday June 07, 2017 @05:46PM (#14510112)
What maintenance overhead? Current and future costs are reduced by making code simpler and cleaner in the first place by using prototypes efficiently.

Also, to be clear, I'm suggesting adding new methods to DOM object prototypes, not changing behavior of existing methods.

Re:A day without JavaScript by ehsanu1 on Wednesday June 07, 2017 @09:29PM (#14511213)
Applications may be able to do this in a controlled manner. Library authors never should.
Re:A day without JavaScript by shakna on Wednesday June 07, 2017 @09:40AM (#14506335)
> Polyfill. So new lib.

So, you don't like the polyfill, created to the specification. Fine, but depending who you target, you might not need it. Plenty of modern browsers have good support.

> And even then. You need to encode params manually.

Or use the Request constructor.

> And of course no middleware, so for special decoding or repeating headers, you end up writing a wrapper.

Request constructor will let you handle the headers quite nicely.

Re:A day without JavaScript by inimino on Wednesday June 07, 2017 @09:24AM (#14506173)
No, a polyfill is not a library. It's a dozen lines, not a thousand.
Re:A day without JavaScript by dragonwriter on Wednesday June 07, 2017 @09:26AM (#14506192)
> No, a polyfill is not a library

Yes, it is.

> It's a dozen lines, not a thousand

A polyfill can be any size, but there's no size minimum to be a library.

Re:A day without JavaScript by inimino on Sunday June 11, 2017 @12:19PM (#14532531)
Overly-literal response.

A polyfill is a short snippet to implement a missing feature. Notably almost all recent additions to JS and DOM have been designed to be polyfillable where possible. Generally that means under a thousand lines, by the way.

A library in this context means a set of functionality built on top of the platform, like jQuery, with its own API, etc. "Use a library" and "use a polyfill" are not the same advice.

A polyfill is not a library.

Re:A day without JavaScript by AstralStorm on Wednesday June 07, 2017 @12:30PM (#14507727)
Some people are mistaking a book (actually a module) for a library.
Re:A day without JavaScript by adtac on Wednesday June 07, 2017 @12:09PM (#14507526)
>Eventually the code will grow to be the size of jQuery anyway.

Um what? jQuery is huge. You won't possibly use everything in it.

Re:A day without JavaScript by emodendroket on Wednesday June 07, 2017 @01:02PM (#14507986)
Well, define "huge." It's like 28KB that your user may already have cached if you use a CDN. https://mathiasbynens.be/demo/jquery-size
Re:A day without JavaScript by adtac on Wednesday June 07, 2017 @01:10PM (#14508044)
I meant huge in terms of functionality. It supports so many things that you can't possibly need everything.
Re:A day without JavaScript by sametmax on Wednesday June 07, 2017 @01:52PM (#14508422)
Event + Ajax + DOM is most of jQuery. And is most what your webapp is. Now I'm more of a fan of Vue.JS + axios myself. But if I have to go minimal, 40ko of jQuery is nothing and save so much trouble. All the "you don't need jquery" thing is done by people doing prototypes that are not tested on most browser or assess in term or ressource vs reward, which is a lot of the projects in the JS community.
Re:A day without JavaScript by emodendroket on Wednesday June 07, 2017 @01:17PM (#14508101)
Oh. Well that's true, but I think the point is more like you end up implementing some significant subset of that, except with homespun code that isn't tested as well.
Re:A day without JavaScript by madeofpalk on Wednesday June 07, 2017 @10:12PM (#14511379)
> Except you need to do Ajax and fetch doesn't cut it

curious as to why you think this? fetch is pretty convenient to use. We created our own wrappers around it, but that basically just consists of ajax = (url) => fetch(url).then(res => res.json())

Re:A day without JavaScript by sametmax on Thursday June 08, 2017 @03:11AM (#14512484)
Exactly, you had to write a wrapper. And the next project will do so. And if you want to save time, and improve reliability, you'll test it, and write doc for the 3rd. And the new team member.

Or you can use the few ko of jQuery.

Re:A day without JavaScript by pharrlax on Wednesday June 07, 2017 @08:17AM (#14505644)
Also, vast majority of users will have a cached copy of jQuery from Google CDN already.

Now bundling it with the rest of your JS, that's indeed a mistake.

Re:A day without JavaScript by nilved on Wednesday June 07, 2017 @08:31AM (#14505742)
CDNs are a lie. The privacy implications outweigh the performance benefits since there are many, many, many CDNs and many, many versions of jQuery. It's rare for users to benefit from caching.
Re:A day without JavaScript by pmlnr on Wednesday June 07, 2017 @08:44AM (#14505856)
I believe this is true, but the world will only be convinced if there are metrics for this. Are you aware of anything that verifies it?
Re:A day without JavaScript by Can_Not on Wednesday June 07, 2017 @06:44PM (#14510434)
Also, the performance benefits from free CDNs that you have no service level agreements are unsubstantiated at best, but you'll notice very quickly how much your site is broken when your CDN is over capacity.