lingz/alphabetical_paginate

With Js enabled there are multiple calls fired on each click

Opened this issue · 1 comments

When the JS option is enabled (always by default) a script tag is appended in the DOM (as for this line here).

This behavior raises two different issues:

  • having the assets pipeline on (as recommended in production) the server will reply with an HTML 404 as the script should really be compiled with the others
  • If the script is served, it will load and bind to the link on the pagination bar an AJAX function.

This leads to this kind of behaviour:
screen shot 2015-03-29 at 17 41 44
Note: this is trigger by a single click, as you see the starting point is the same of all 4.

When the user clicks a couple of letters on the bar a massive number of requests start to hit the server.

While there are some solutions to fix such behavior it looks to me that this kind of things should really be implemented by the user himself rather than be in the bundle.

For instance a similar gem such will_paginate works this way - no AJAX support in the bundle - and adapt it to work with AJAX is not that hard: http://asciicasts.com/episodes/174-pagination-with-ajax

I'd propose to remove such option, or at least ship the JS file as a separate asset that can be included but no automagically included as it does right now.
Documenting on the WIKI how to enable it seems a reasonable solution to me and will make also the support of this gem much simpler.

My only concern here is A) it would break backwards compatibility, and B) it does add some complexity in requiring another step.

Perhaps we could make it so the script tag is served outside the boundary of the reloaded html.

A current situation exists in that the dev can turn off js in the options parameter and implement the functionality themselves.