News for hackers. Stuff that matters.
Re:Show HN: Make your site’s pages instant in one minute by xpose2000 on Saturday February 09, 2019 @01:24PM (#19123750)
I've been testing it for the past 30 minutes or so and found that it doesn't cause the same problems that InstantClick did. (Which was javascript errors that would randomly occur.) I'll limit it to a small subset of users to see if any errors are reported but there is a good chance this could go live for all logged in users. Maybe even all website visitors if all goes well.

Seems to have no impact on any javascript, including ads. Pages do load faster, and I can see the prefetch working.

Just make sure you apply the data-no-instant tag to your logout link, otherwise it'll logout on mouseover.

Re:Show HN: Make your site’s pages instant in one minute by hn_throwaway_99 on Saturday February 09, 2019 @01:41PM (#19123835)
> Just make sure you apply the data-no-instant tag to your logout link, otherwise it'll logout on mouseover.

Logout links should never be GETs in the first place - they change states and should be POSTs.

Re:Show HN: Make your site’s pages instant in one minute by slim on Saturday February 09, 2019 @02:27PM (#19124078)
POSTs are not Links. And Logout service is indempotent even if you can consider it changes the state of the system
Re:Show HN: Make your site’s pages instant in one minute by nardi on Saturday February 09, 2019 @10:57PM (#19126293)
Lots of people in this thread confusing “idempotent” with “safe” as specified in the HTTP RFC: https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Re:Show HN: Make your site’s pages instant in one minute by kbirkeland on Sunday February 10, 2019 @01:32AM (#19126630)
FWIW RFC 2616 was obsoleted by the newer HTTP/1.1 RFCs: https://tools.ietf.org/html/rfc7231#section-4.2
Re:Show HN: Make your site’s pages instant in one minute by amenod on Sunday February 10, 2019 @05:08AM (#19127149)
Which still doesn't change GP's point though:

> In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe".

(there's an exception listed too, but doesn't apply to logout)

EDIT: I know of someone who made a backup of their wiki by simply doing a crawl - only to find out later that "delete this page" was implemented as links, and that the confirmation dialog only triggered if you had JS enabled. It was fun restoring the system.

Re:Show HN: Make your site’s pages instant in one minute by kbirkeland on Monday February 11, 2019 @12:44AM (#19132336)
I don't know why you think I'm contradicting them. I was just pointing out that there are newer RFCs. They also happen to have a stronger and more complete definition of safe methods.
Re:Show HN: Make your site’s pages instant in one minute by Gaelan on Saturday February 09, 2019 @02:57PM (#19124229)
Ok, so make it a form/button styled to look like a link.
Re:Show HN: Make your site’s pages instant in one minute by glacials on Saturday February 09, 2019 @02:30PM (#19124092)
Idempotency is not the issue, the issue is that a user might hover over the logout link, not click it, then move on to the rest of the site and find they are logged out for no reason.
Re:Show HN: Make your site’s pages instant in one minute by leesalminen on Saturday February 09, 2019 @02:41PM (#19124148)
Right, which is why the included library includes an HTML attribute to disable prefetch on a given link.
Re:Show HN: Make your site’s pages instant in one minute by pbreit on Saturday February 09, 2019 @05:12PM (#19124987)
OP’s point was that logout should not be implemented with a link/GET but instead with a button/POST for exactly this reason.
Re:Show HN: Make your site’s pages instant in one minute by leesalminen on Saturday February 09, 2019 @05:45PM (#19125168)
A logout action is idempotent, though. You can't get logged out twice. In my opinion, that's the use case for a GET request.

I just checked NewRelic, Twilio, Stripe and GitHub. The first 3 logged out with a GET request and GitHub used a POST.

Re:Show HN: Make your site’s pages instant in one minute by zepolen on Saturday February 09, 2019 @07:40PM (#19125695)
Idempotency has nothing to do with it. Deleting a resource is idempotent as well. You wouldn't do that via GET /delete

A GET request should never, ever change state. No buts.

Just because a bunch of well known sites use GET /logout to logout does not make it correct.

Doing anything else as demonstrated in this and other cases breaks web protocols, the right thing to do is:

GET /logout returns a page with a form button to logout POST /logout logs you out

Re:Show HN: Make your site’s pages instant in one minute by derefr on Sunday February 10, 2019 @01:06PM (#19129048)
Depends on your definition of “state.” A GET to a dynamic resource can build that resource (by e.g. scraping some website or something—you can think of this as effectively what a reverse-proxy like Varnish is doing), and then cache that built resource. That cache is “state” that you’re mutating. You might also mutate, say, request metrics tables, or server logs. So it’s fine for a GET to cause things to happen—to change internal state.

The requirement on GETs is that it must result in no changes to the observed representational state transferred to any user: for any pair of GET requests a user might make, there must be no change to the representation transferred by one GET as a side-effect of submitting the other GET first.

If you are building dynamic pages, for example, then you must maintain the illusion that the resource representation “always was” what the GET that built the resource retrieved. A GET to a resource shouldn’t leak, in the transferred representation, any of the internal state mutated by the GET (e.g. access metrics.)

So, by this measure, the old-school “hit counter” images that incremented on every GET were incorrect: the GET causes a side-effect observable upon another GET (of the same resource), such that the ordering of your GETs matters.

But it wouldn’t be wrong to have a hit-counter-image resource at /hits?asof=[timestamp] (where [timestamp] is e.g. provided by client-side JS) that builds a dynamic representation based upon the historical value of a hit counter at quantized time N, and also increments the “current” bucket’s value upon access.

The difference between the two, is that the resource /hits?asof=N would never be retrieved until N, so it’s transferred representation can be defined to have “always been” the current value of the hit counter at time N, and then cached. Ordering of such requests doesn’t matter a bit; each one has a “natural value” for it’s transferred representation, such that out-of-order gets are fine (as long as you’re building the response from historical metrics,

Re:Show HN: Make your site’s pages instant in one minute by zepolen on Monday February 11, 2019 @06:15AM (#19133603)
Don't be a wise ass, with that definition state changes all the time in memory registers even when no requests are made.

> So, by this measure, the old-school “hit counter” images that incremented on every GET were incorrect

Yes they are incorrect. No Buts.

Two requests hitting that resource at the same exact timestamp would increase the counter once if a cache was in front of it.

Re:Show HN: Make your site’s pages instant in one minute by klyrs on Saturday February 09, 2019 @11:30PM (#19126373)
That brings me back to the year 2001, when my boss's browser history introduced Alexa to our admin page and they spidered a bunch of [delete] links. cough cough good thing it was only links from the main page to data, and not the actual data. I spent the next few days fixing several of problems that conspired to make that happen...
Re:Show HN: Make your site’s pages instant in one minute by Piskvorrr on Sunday February 10, 2019 @06:40AM (#19127413)
As in, anybody with a link to /delete could delete things? No identification/authentication/authorization needed?
Re:Show HN: Make your site’s pages instant in one minute by klyrs on Sunday February 10, 2019 @11:46AM (#19128488)
> I spent the next few days fixing several of problems that conspired to make that happen...

Yes, I was a total n00b in 2001. But then, so was e-commerce.

Re:Show HN: Make your site’s pages instant in one minute by klyrs on Sunday February 10, 2019 @05:14PM (#19130444)
and fwiw, I knew exactly how bad our security was... I kept my boss informed, but he had different priorities until Alexa "hacked" our mainpage :p
Re:Show HN: Make your site’s pages instant in one minute by BorRagnarok on Monday February 11, 2019 @07:33AM (#19133931)
If you're not allowed to change state on GET requests, how do you implement timed session expiration in your api? You can't track user activity, in any way, on get requests, but still have to remember when he was last active.
Re:Show HN: Make your site’s pages instant in one minute by NewEntryHN on Saturday February 09, 2019 @06:47PM (#19125456)
Idempotence is for PUT requests. GET requests must not have side effects.
Re:Show HN: Make your site’s pages instant in one minute by BorRagnarok on Monday February 11, 2019 @07:28AM (#19133904)
I've heard this "get requests shouldn't have side effects" argument before, but I don't think it works. At least, not for me, or I'm doing something wrong.

For example: Let's implement authentication, where a user logs in to your api and receives a session id to send along with every api call for authentication. The session should automatically be invalidated after x hours of inactivity.

How would you track that inactivity time, if you're not allowed to change state on get requests?

Re:Show HN: Make your site’s pages instant in one minute by hateful on Saturday February 09, 2019 @06:25PM (#19125375)
I think this is the argument for PUT instead of POST, not GET instead of POST.
Re:Show HN: Make your site’s pages instant in one minute by hueving on Saturday February 09, 2019 @11:45PM (#19126404)
You're confusing idempotency and side effects. A GET should not have any side effects, even if they are idempotent.
Re:Show HN: Make your site’s pages instant in one minute by dalore on Wednesday February 13, 2019 @11:43AM (#19154363)
It's not about idempotency, but about side effects. The standards mention if it will cause side effects use POST. Logging out does cause side effect (you lose your login) and hence should be a POST.

In the old days it might have been acceptable to get away with a GET request but these days thanks to prefetching (like this very topic) it's frowned upon.

https://stackoverflow.com/questions/3521290/logout-get-or-po...

Re:Show HN: Make your site’s pages instant in one minute by pbreit on Sunday February 10, 2019 @12:31AM (#19126504)
GET is also supposed to be “safe” in that it doesn’t change the resource which a logout would seem to violate.

The whole reason this is supposed to be the case is in order to enable such functionality as this instant thing.

Re:Show HN: Make your site’s pages instant in one minute by abathur on Saturday February 09, 2019 @06:42PM (#19125433)
Also: sometimes a site is misbehaving (for myself, or maybe for a user we're helping) and it's helpful to directly navigate to /logout just to know everyone is rowing in the same direction.

Using a POST, especially if you're building through a framework that automatically applies CSRF to your forms, forecloses this possibility (unless you maintain a separate secret GET-supporting logout endpoint, I guess).

Re:Show HN: Make your site’s pages instant in one minute by Guest10928391 on Sunday February 10, 2019 @05:56AM (#19127280)
When I originally started my community site I used GET for logout. However, users started trolling each other by posting links to log people out. It wasn't easy to control, because a user could post a link to a completely different site, which would then redirect to the logout link. So, I switched to POST with CSRF and never had another issue.
Re:Show HN: Make your site’s pages instant in one minute by enedil on Saturday February 09, 2019 @02:41PM (#19124144)
That's exactly the problem with idempotency.
Re:Show HN: Make your site’s pages instant in one minute by winstonewert on Saturday February 09, 2019 @02:48PM (#19124187)
actually, no. Idempotency means that you can safely do the same operation multiple times with the same effect as doing it once. That's a different issue than the no-side-effects rule which GET is supposed to follow.
Re:Show HN: Make your site’s pages instant in one minute by ezequiel-garzon on Saturday February 09, 2019 @02:48PM (#19124182)
Thanks, how did you find out about data-no-instant tag?
Re:Show HN: Make your site’s pages instant in one minute by sgustard on Saturday February 09, 2019 @03:11PM (#19124312)