Resources

Stimulus Content Loader - https://github.com/stimulus-components/stimulus-content-loader

Update: The values have changed in the latest version.

data-content-loader-url
data-content-loader-refresh-interval

has been changed to 

data-content-loader-url-value
data-content-loader-refresh-interval-value
Download Source Code

Summary

# Terminal
rails webpacker:install:stimulus
yarn add stimulus-content-loader

# app/javascript/controllers/index.js
import ContentLoader from 'stimulus-content-loader'
application.register('content-loader', ContentLoader)

# views/welcome/index.html.erb
<div data-controller='content-loader'
     data-content-loader-url='<%= slows_path %>'>
  Loading slow controller...
</div>

<div data-controller='content-loader'
     data-content-loader-url='<%= bitcoins_path(currency: 'USD') %>'
     data-content-loader-refresh-interval='5000'>
  Loading bitcoin...
</div>

# config/routes.rb
  resources :slows, only: :index
  resources :bitcoins, only: :index

# slows_controller.rb
class SlowsController < ApplicationController
  def index
    sleep 5
    # render plain: 'Loaded!'
    world = "world"
    render partial: 'slows/index', locals: { world: world }
  end
end

# bitcoins_controller.rb
class BitcoinsController < ApplicationController
  def index
    url = URI("https://blockchain.info/ticker")
    response = Net::HTTP.get(url)
    data = JSON.parse(response)
    render partial: 'index', locals: { data: data, currency: params[:currency] || 'USD' }
  end
end

# views/slows/_index.html.erb
Hello <%= world %>!

# views/bitcoins/_index.html.erb
<%= "Bitcoin (#{currency}): #{data[currency]['last']}" %>