StepRender
It is very easy to enable lazy loading of partial with scroll in views.
You only use step_render
method instead of render
method.
Likewise, you can lazy load a fragment cache.
Installation
Add this line to your application's Gemfile:
gem 'step_render'
And then execute:
$ bundle
Usage 1: Lazy Load Partial
1. Load javascript library
This plugin depends on lazysizes.
If you do not import lazysizes to your application, load import_step_render
method in required view.
Example
application.html.erb
<head>
~~~
~~~
<%= import_step_render %>
~~~
</head>
2. Add to routing
Add the following line to the routes.rb
.
Example
routes.rb
Rails.application.routes.draw do
~~~
mount_step_render
~~~
3. Use step_render
method instead of render
method
Replace render
helper method used to rendering the partial with step_render
.
Partial must be specified as an absolute path.
Example
app/views/top/index.html.erb
<%= step_render 'top/partial_name' %>
Usage 2: Lazy Load fragment cache
1. Load javascript library
2. Add to routing
3. Use step_cache
method instead of cache
method
Replace cache
helper method used to fragment cache with step_render
.
Example
app/views/top/index.html.erb
<%= step_cache 'cache_key', skip_digest: true, expires_in: 24.hours %>
~~~
~~~html tags
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.