Rails turbolinks long request doesn't show page load
Asked Answered
I

1

9

Using turbolinks in Rails, if a request is taking a long time, either expectedly or not, the browser does not have the usual cues to show that anything is happening at all.

Intricacy answered 9/3, 2013 at 11:58 Comment(0)
I
10

I have created a gist which works around this issue using a loading dialog which automatically pops up if the request is taking more than 500ms, which is configurable.

https://gist.github.com/cpuguy83/5016442

@PageSpinner =
  spin: (ms=500)->
    @spinner = setTimeout( (=> @add_spinner()), ms)
    $(document).on 'page:change', =>
      @remove_spinner()
  spinner_html: '
    <div class="modal hide fade" id="page-spinner">
      <div class="modal-head card-title">Please Wait...</div>
      <div class="modal-body card-body">
        <i class="icon-spinner icon-spin icon-2x"></i>
        &emsp;Loading...
      </div>
    </div>
  '
  spinner: null
  add_spinner: ->
    $('body').append(@spinner_html)
    $('body div#page-spinner').modal()
  remove_spinner: ->
    clearTimeout(@spinner)
    $('div#page-spinner').modal('hide')
    $('div#page-spinner').on 'hidden', ->
      $(this).remove()

$(document).on 'page:fetch', ->
  PageSpinner.spin()
Intricacy answered 9/3, 2013 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.