Turbolinks for Rails (like pjax)
github.com
github.com
I may be misleading myself, but it's rare (on a desktop browser, at least) that it's the page rendering time that I really notice: far more significant is usually the latency, or the time taken to transfer the significant proportion of a megabyte of HTML that's smothering a few kilobytes of text.
On the downside, it replaces something that just works with something that ... mostly just works. See elsewhere on this page: "Loads blank white screens in firefox 15" / "This is now fixed". And that's the problem: you've replaced something that works in every browser with something that you have to (or someone has to) test in every browser, and whose failure modes must all be handled. What happens when you click on a "turbolink" on an overloaded server, for example? My experience so far has been that this kind of enhanced link is usually faster, but the probability of nothing happening in response to a click is not insignificant.
I'm aware that I probably sound like an old grouch.
We use it for pages that have low latency (50-100ms) and a light weight (<100KB) for Basecamp. It makes a big different for apps built like that. This is a project that works with and encourages you to build apps like that.
Yes you can write single page apps, but with Rails you get the speed of single page apps with the ease of traditional Rails
If Rails 4 is all about PJAX, my hope for Rails 5 is it's the one that embraces fat-client JS apps and exposes JSON services in a standard way, so they can easily be consumed by convention-based frameworks such as EmberJS.
Pretty sure DHH would say not a chance.
I was asking him about http://joosy.ws. I was excited about their approach of tying the client side javascript UI into rails. Not just using another generic javascript UI framework and using REST models, but tying into the models of Rails and then making an intelligent linkup to the javascript front end. I think the approach could be the future.
But if you're going to use Rails for the view, the focus will remain on making Basecamp-style apps (turbolinks, russian caching dolls, etc).
That being said, and I'm only putting this out there, but lisp-esque continuations in the browser for this sort of stuff?
Also, part of me thinks that if you require this sort of thing, Rails is the wrong tool. Rails is great, but a full stack framework is pretty intensive for this sort of thing.
Probably not too hard to add it to it. Maybe i'll get around to making up a patch myself if nobody else does.
But I'd be a lot happier with turbolink on a link-by-link opt-in basis.
Is it a widely accepted convention to maintain scroll position between PJAX page loads? When a large portion of the page content is changing, one might expect the page to scroll back to the top.
The matching nodes from the old page are replaced.
I imagine you have to rebind all your $(function() {}) code to the page:update event (and maybe also leave it bound to document.ready for the initial page load??), but I'm not quite sure the best way to do that.
Edit: ok is rough but it seems to work
$(function() {
alert("document.ready");
});
$(document).bind('page:change', function() {
alert("page:change");
}); $(window).bind('pjax:end', ->
# document ready code
) $(function() {
pageLoad();
});
$(window).bind('page:change', function() {
pageLoad();
});
However, it calls the originally set pageLoad() on every subsequent update. Maybe if there was some way to clear the function before it replaces the content?Might be easier if your code exclusively uses jquery's ready rather than native DOM onload or whatever.
But yeah, either way, this is a bunch of added logic that can go wrong, I'm not super enthused about it myself.
https://github.com/rails/turbolinks/blob/master/lib/assets/j...
For various reasons we don't use coffeescript in our projects but now if we want to use turbolinks (which sounds great) we'll get a coffeescript dependency.
But e.g. jquery-rails https://github.com/rails/jquery-ujs is written in JS not CS, so I can use all the jQuery integration in Rails without using CS.
With turbolinks being written in CS if I want to use the full power of Rails+JS I need to add CS to my project.
Having either in a gem is rare, but sensible if the gem wants to include a client to interact with the service it provides.
From what I can think there will be two broad use cases:
1) Sibling pages within a section will often share RHS and header content. So makes sense to replace the inner area where the actual page content lives and leave the rest alone.
2) Cases where the above doesn't hold or it's too complicated to care about, so load in the whole body.
I'm sure DHH chose the #2 rule because #1 turns out to cause a can of worms?
And the inevitable vs PJAX conversation (ie: is it flexible enough? Does it need to be?)
> Work left to do
> CSS/JS asset change detection and reload
how about <script>s at end of <body> for load performance instead of in <head>?
there's always edge cases. it's asking for trouble, sez me.