pjax vs turbolinks vs cache_digests to improve rails speed? - ruby-on-rails

I've done some reading about the various options for improving the speed of a rails site.
The following libraries seem promising:
pjax
turbolinks
cache_digests
However, it seems like they try to do many similar things.
Can/Should you use them in tandem? Are there problems that would arise in doing so?
Are there cases where one or the other is better than the rest? (And what are they?)
Is there something superior to all three I should check out instead?

I prefer pjax. It's easy to use and very fast. You just have to define a pjax-container which will be replaced every request.
Turbolinks instead does replace the whole body. I don't like that very much. But that's matter of taste. It will be part of Rails 4.

cache_digests is not something that can be compared with pjax or turbolinks.
cache_digests enhances Rails caching to allow for Russian-doll caching.
Turbolinks tends to be a bit more straightforward and doesn't require jquery.
Pjax is configurable but required jquery.

Related

backbone vs turbolinks for search engine with rails 3.2

I'm working on a small search engine with tire and elastic search. I just started the project and I would like the search to be as fast as possible.
What technology should I use for this purpose, turbolinks or backbone.js?
Also. I would like to know how I can solve the problem of "Seo" with these technologies.
thanks
Using Backbone with ajax requests will be slightly faster than using Turbolinks.
However, Turbolinks will provides SEO by default, whereas you have to do a lot of work to make Backbone and SEO work (See this StackOverflow question)
You'll also have to write a lot of JavaScript if you use Backbone compared to writing hardly any JavaScript if you use Turbolinks.
It's really up to you to weigh the pros and cons and decide which option is better for your situation though.

Is it a good idea to use emberjs only in some pages when using rails?

I have a rails app that has pretty standard things, except for two pages that require a lot of JS.
I was wondering if it's a good choice to use ember just for those two pages while keeping Rails standard for everything else? Or should I rewrite everything in emberjs + rails as API backend?
This is really a case-by-case situation. Why do those two pages require a lot of JS? The answer is probably "because of an implementation decision you made." Adding Ember to the mix is probably going to prompt you to revisit a lot of implementation decisions to reconsider which tools are appropriate to use in which places.

Rails future & Javascript

David H.H. announced recently that jquery is going to be the default in Rails 3.1, and that Prototype helpers / RJS are going into a gem.
What does that mean for the future? Should we progressively forget about things like javascript helpers, RJS, and all these fun parts of rails? And start coding with jquery/json in mind?
I'm not against that at all, but I have to admit I find RJS really fun to use...
Yes, unobtrusive JavaScript has won. Many people write now directly JS / jQuery code in ERB templates. jQuery code to replace some DOM node with a partial is only slightly longer than equivalent RJS code. Regarding JS helpers, it should be quite easy to replace all of them with unobtrusive JS code. Check how data-remote is handled in jQuery Rails driver.
This trend makes sense because web apps have more and more JS code which cannot be written in RJS. It is better to use two languages than three.
If you don't like JavaScript syntax then check out CoffeeScript. Which will be definitely more popular than RJS.
Long term future probably belongs to pure JS frameworks like SproutCore. Server side will process only JSON data. However these new techniques will be used only in new apps. Generally it doesn't make sense to upgrade existing apps to the new model.

Rails Prototype and Unobtrusive Javascript

I've been programming rails for only a few months and was first introduced to RJS in 2.3.8 rails. Though things have changed slightly and am a little confused with this "unobtrusive javascript". From reading google, I'm understanding it as like removing the javascript inline to a seperate file.
From what I understood of .rjs was it was already doing this.
Can someone explain the difference, if there is one? I'm still trying to make that leap over to unobtrusive JS cause it seems like it's the rails 3 way but I'm having trouble making that jump. Or is unobtrusive javascript "pure" js and not like the ruby way as I've understood that .rjs is a wrapper for javascript. Should I take the clue that I need to start learning java script? I know very little of javascript.
Thanks in advance for any advice/tips.
Unobtrusive means not doing things inline, as you said. RJS is something different, basically ruby helpers that generate javascript. What unobtrusive means for rails is that instead of generating js inline, it will instead decorate the dom objects with information enough to figure out what to do, and then use event delegation as an alternative technique to just dumping a script tag into the middle of the page.
This results in much cleaner output, and potentially better performance, both client side (don't have to re-run javascript all the time if you are using event delegation), and ajax-wise (not doing things inline means you don't need to push javascript over the wire as well as your html).
RJS is a whole different thing, and was pretty much un changed by that move. Typically, I find that people who aren't that familiar with how javascript works prefer the rjs approach, since it just does the job. If you are really serious about your js, chances are you will either be using js.erb files, or just doing returning json from the server and dealing with everything else fully client side.

Latest and accepted ajax techniques in Rails

What is the present state of Rails Ajax?
What frameworks and technologies should one use when working with Rails now?
Rails seems to evolve so rapidly that one might not be able to keep up.
Is it prototype and RJS or something else?
The point of RJS is that you don't really need to keep up with a framework, that the javascript functions are abstracted into Ruby for you to use.
That said, prototype is still the default choice, but there are plugins (http://ennerchi.com/projects/jrails) to implement RJS functions in jQuery. Of course, you could forgo the abstractions entirely and write the javascript however you'd like.
Personally, I find myself trying to stick to the Rails' default methods, and if I need a method that goes outside what RJS provides, making sure I am implementing it properly (ie. not duplicating what someone else has done), and usually doing it in prototype as to not have to load multiple javascript frameworks.
As said before, Rails' default javascript library is (and will probably always be) Prototype/Scriptaculous. However, when Rails 3.0 is released sometime around the beginning of May, it should be more accepting of other libraries such as jQuery.
If you don't like RJS, you can use a .js.erb extension and write javascript that will be sent through the erb template engine. This is my preferred way of doing things these days. You can see an example of this, and jQuery in this episode of Railscasts.

Resources