News for hackers. Stuff that matters.
Re:Intercooler.js – Simple AJAX Using HTML Attributes by detaro on Sunday July 08, 2018 @03:44PM (#17485779)
Re:Intercooler.js – Simple AJAX Using HTML Attributes by cyberferret on Sunday July 08, 2018 @08:15PM (#17487078)
Turbolinks looks neat, but our Ruby app selectively includes CSS and Javascript snippets outside the <body> tag depending on what page is loaded (using :content_for declarations in our templates). I am guessing that Turbolinks will not work for us in this case, as the relevant external files will not be called on page load?
Re:Intercooler.js – Simple AJAX Using HTML Attributes by nicostouch on Sunday July 08, 2018 @09:58PM (#17487454)
turbolinks swaps out the <body> and merges the <head> tags of the incoming page with the existing <head> tag.
Re:Intercooler.js – Simple AJAX Using HTML Attributes by cousin_it on Sunday July 08, 2018 @03:48PM (#17485804)
Neat! Though the point of my idea is having animated transitions between pages, by replacing contents of sticky elements and letting their CSS transitions work as usual. As far as I can tell, turbolinks doesn't do that.
Re:Intercooler.js – Simple AJAX Using HTML Attributes by detaro on Sunday July 08, 2018 @04:13PM (#17485938)
I think it always replaces the entire body element, not parts of it, yes
Re:Intercooler.js – Simple AJAX Using HTML Attributes by b_f on Sunday July 08, 2018 @07:00PM (#17486772)
Re:Intercooler.js – Simple AJAX Using HTML Attributes by cousin_it on Sunday July 08, 2018 @07:19PM (#17486864)
Yeah, well... that still requires you to write custom JS. The thing I'm imagining would be based only on markup - which sticky ids exist in both pages. But the idea is really similar, thanks for the link!
Re:Intercooler.js – Simple AJAX Using HTML Attributes by victor106 on Sunday July 08, 2018 @03:58PM (#17485860)
Turbolinks is cool but it seems more tied to only a rails backend. Anyone know how to use it with Java?
Re:Intercooler.js – Simple AJAX Using HTML Attributes by nicostouch on Sunday July 08, 2018 @10:11PM (#17487490)
It's independent of Rails. It simply hooks the all calls to <a href> tags and replaces them with ajax get requests to the url.

It works really nice with Rails because of how easy Rails makes it return a piece of javascript to the page (this is called SJR) so there is some magic included for making form submissions work which is part of the Rails turbolinks gem. The javascript that the server returns to the page essentially calls Turbolinks.visit("/url-form-submission-would-redirect-to-after-completion") so that the expected navigation takes place. It's quite clever. I think you would have to replicate that in the Java world to get the full experience. This SO answer alludes to how you might replicate SJR https://stackoverflow.com/questions/26750738/java-spring-ret...

So I think out of the box you can expect clicking links to work (and that alone provides a great speedup), but ajax form submissions will require some work. If you look at some articles on how form submissions with turbolinks make use of SJR you could likely figure it out and implement it. It's overall not a very complicated mechanism.

I suppose Rails .erb templating engine also has some helpers which the form submission side of turbolinks relies on. Namely it includes a data attribute data-remote and that's the thing turbolinks hooks into to prevent the default behavior of the form submission and and instead fire the ajax request. In theory so long as your forms include that it will work if you have the SJR stuff in place on your back-end.

You could definitely roll full support for it.

Re:Intercooler.js – Simple AJAX Using HTML Attributes by PascalW on Sunday July 08, 2018 @05:03PM (#17486185)
It's not tied to Rails at all. I'm using it with a Phoenix backend. You just include the JS and presto!
Re:Intercooler.js – Simple AJAX Using HTML Attributes by elcritch on Sunday July 08, 2018 @06:07PM (#17486513)
So you don’t you need to configure the Phoenix backend or whatnot? That’s even more awesome!