Live data from Hacker News

The Single Piece of JavaScript on HN

blog.watchandcode.com

161–170 of 195 posts

Re: The Single Piece of JavaScript on HN

#161

Earlier quoted context omitted.

Lol. For hiding a voting arrow after it's clicked. Yes, you're right. You don't need any of that stuff. But if you were to write an entire app in the style of those two functions, things would fall apart. That's not even a hypothetical, it's been proven over and over again that it doesn't work. How is everyone agreeing with you? Is there that much JS fatigue that we're looking at the equivalent of a horse-drawn carri…

I think the point is that there's actually little wrong with using standard HTML forms and hyperlinks most of the time. There is an increasing trend to move the whole website to the client side to be handled entirely by the JavaScript as a single actual page. Personally I find most websites work better with a simple round trip to the server to fetch more HTML. So actually building an entire system in this style isn't…

> Personally I find most websites work better with a simple round trip to the server to fetch more HTML.

> you just only write JavaScript for the cases where there is a real legitimate benefit to doing so

The snippet above only works because HN is so simple, normally the rule of thumb is if you are going to use JS to change the DOM at all then you need to render it in the first place using JS or else you are double-implementing the render logic and you open yourself up to changing one implementation and not the other. For hiding arrows sure this works but 99.999% of the time it's a very bad idea to use JS to change the dom to a state that the server would otherwise render on a page reload. You may feel that a round trip works better but that's not what users expect or will tolerate most of the time. That kind of thinking feels very close to people who think CRUD is all you need to build an app. Sure you can build an app with just that but thinks break down very quickly.

Re: The Single Piece of JavaScript on HN

#162

Earlier quoted context omitted.

Is that the fault of HN or Windows Phone?

HN. Makes me thinkg of that great rant my Linus about breaking userspace by "fixing" a "bug" If you break something for a significant portion of your users, even if it's caused by someone/something else doing something dumb, it's still your fault

In the case of the web we have standards which describe correct behaviour. Is HN not following them?

Re: The Single Piece of JavaScript on HN

#163

Earlier quoted context omitted.

Well there appear to be two things stopping this: - Hiding two elements on the page (one can be hidden with the CSS :visited selector) - Remaining with your position on the page whilst also sending a message to the server and without opening new windows. So the only way to do the task is to send a full request to the server which would return you to the page with the buttons correctly disabled. Extra load on the serv…

1. I think you could hide both with some adjacent sibling selector trickery. (Assuming you can select a sibling of a :visited) 2. Could you set a background image on a visited to a 1x1 gif of the tracking url? Not sure if CSS lets you do that. I know there are some limitations around :visited specifically to stop privacy snooping, but out so I can't look up the specifics right now.

Ah that might work

Re: The Single Piece of JavaScript on HN

#164

Earlier quoted context omitted.

But GET requests should be idempotent.

But it is idempotent in this case. The server keeps track of your votes, so regardless of the number of times you do the same GET, the result is the same.

At the moment, but in the future the browser might decide to prefetch the pages behind these links, hence voting against your will.

> (...) we may expand link prefetching support to include prefetching tags, which include a relation type of next or prefetch in the future.

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Link_prefe...

Re: The Single Piece of JavaScript on HN

#165

Earlier quoted context omitted.

Is that the fault of HN or Windows Phone?

HN. Makes me thinkg of that great rant my Linus about breaking userspace by "fixing" a "bug" If you break something for a significant portion of your users, even if it's caused by someone/something else doing something dumb, it's still your fault

> for a significant portion of your users

Windows Phone users are a significant portion of HN users?

Re: The Single Piece of JavaScript on HN

#166

I see a lot of comments here about how not having js on the page is a great thing and lets get back to the old days. Lets be frank here, HN's UI is not good. At the very least it needs collapsible comments and responsiveness to mobile. The fact that HN is a success is despite its bad UI, or maybe because of the many HN readers out there that fix all the broken stuff on the page. While js on sites have surely overgrow…

HN's UI is clear, accessible, and uncluttered. If you want something different, they expose an API which everyone and their mother has written a client with, including native apps for mobile. The only JS on the site is in place to reduce the page reloads you were worried about. What is the problem here?

It's certainly not "uncluttered" on mobile, where the text and vote buttons are so tiny and crowded together that it's super easy to tap the wrong thing.

Re: The Single Piece of JavaScript on HN

#167

Earlier quoted context omitted.

What's most fascinating to me about this isn't the simplicity, it's that this code has lived for so long with almost no changes. It's a great counter-example to all the recent articles about JavaScript fatigue. It's good for us to see real examples of sites that aren't caught up in the framework of the week hype. At the end of the day we're trying to make stuff that works. ES5 vs ES6, React vs Angular vs. Ember vs. A…

Lol. For hiding a voting arrow after it's clicked. Yes, you're right. You don't need any of that stuff. But if you were to write an entire app in the style of those two functions, things would fall apart. That's not even a hypothetical, it's been proven over and over again that it doesn't work. How is everyone agreeing with you? Is there that much JS fatigue that we're looking at the equivalent of a horse-drawn carri…

Nowhere did I tell people to write an entire app in the style of hide and vote like you're implying.

In my comparisons I mention a lot of choices people might make, like Angular vs. Ember vs. React that are ultimately meaningless to the success of your product. I think this is what's resonating with a lot of people.

Re: The Single Piece of JavaScript on HN

#168

Earlier quoted context omitted.

Not just you. I don't see why this warrants a 12 minute video.

I'll give you one reason. I've never done any front-end stuff before. But maybe a month ago, I got curious. Perhaps because I read HN everyday. And if you try to immerse yourself in the front-end world, you get 'yeah, learn HTML/CSS/JS, BUT, also learn Angular, React, JQuery, et. al...' It's good to get a reminder that Javascript in and of itself is a capable language. I'm sure I'm not the only one in this camp. Mayb…

Thanks for the perspective.

This is why I encourage all developers to take some time to teach new people. The "everyone knows this obviously" attitude goes away very quickly if you start doing this.

The aim of the video was to make it accessible to just about everybody. So if you know this stuff you can watch the first minute and stop the video and get value out of it. On the other hand, if you're a beginner and you just did Codecademy, you can watch it through and follow it too.

Re: The Single Piece of JavaScript on HN

#169

I see a lot of comments here about how not having js on the page is a great thing and lets get back to the old days. Lets be frank here, HN's UI is not good. At the very least it needs collapsible comments and responsiveness to mobile. The fact that HN is a success is despite its bad UI, or maybe because of the many HN readers out there that fix all the broken stuff on the page. While js on sites have surely overgrow…

Collapsible comments are driving me mad. It's wrong on all levels on a forum-like page where I go for the comments and the comments only.
Post reply on HN