Rails turbolinks long request doesn't show page load

后端 未结 1 1827
[愿得一人]
[愿得一人] 2021-02-15 04:19

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.

1条回答
  •  孤城傲影
    2021-02-15 04:36

    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: '
        
      '
      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()
    

    0 讨论(0)
提交回复
热议问题