Lazyloading Image in Rails
Lazy Load is delays loading of images in long web pages. Images outside of viewport are not loaded until user scrolls to them. This is opposite of image preloading.
Using Lazy Load on long web pages will make the page load faster. In some cases it can also help to reduce server load.
Installation
Add this line to your application's Gemfile:
gem 'lazyload-image-rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lazyload-image-rails
Usage
Lazy Load depends on jQuery
in application.js add following
= require jquery.lazyload
You must alter your image tags. Address of the image must be put into data-original attribute. Give lazy loaded images a specific class. This way you can easily control which images plugin is binded to.
<img class="lazy" data-original="img/example.jpg" width="640" height="480">
$(function() {
$("img.lazy").lazyload();
});
####For more information please refer:
- http://www.appelsiini.net/projects/lazyload
- https://github.com/tuupola/jquery_lazyload
Contributing
- Fork it ( https://github.com/abhisheksunkuru/lazyload-image-rails/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request