jQuery Lazy

A lightweight but powerful delayed content, image and background lazy-loading plugin for jQuery

What is Lazy?

Lazy is a fast, feature-rich, extensible and lightweight delayed content loading plugin for jQuery. It's designed to speed up page loading times and decrease traffic to your customers and users by only loading the content in view.

Designed for everything

Lazy supports images and backgrounds by default or any other content by custom loaders you like to implement.

It's a time saver

Lazy will decrease your development time and save traffic and loading times for your users and customers.

Scroll in every way

You can use Lazy in all vertical and horizontal scroll ways, it will only load the elements in threshold.


Lazy works well on every tested mobile devices so far and supports retina and other high density displays as well.

Easy to customise

Lazy delivers a mighty configuration, many callbacks, public functions and custom loaders for full control on everything.

Fully free & open source

All sources are available on GitHub. Feel free to report bugs, ask for new features or even contribute to Lazy by yourself there!

Wide compatibility range


  • Retina support
  • Fully open source
  • Scroll in all directions
  • Different callbacks
  • Implement custom loaders
  • Image placeholders
  • Use effects
  • Throttled
  • Public functions
  • Delayed loading
  • Many instances
  • Use inside containers
  • Event support
  • Mighty configuration

Get Started


First of all, you will need a copy of jQuery to use Lazy successfully in your project. If you get this you can install Lazy by different ways. Select your favorite below.

Download and save one of two available files to include Lazy to your page, either the development or the minified version beside of jQuery.

    <script type="text/javascript" src="jquery.lazy.min.js"></script>

Lazy is available over cdnjs and jsDelivr CDN and can be directly included to every page.

    <!-- cdnjs -->
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/0.6.1/jquery.lazy.js"></script>

    <!-- jsDeliver -->
    <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazy/0.6.1/jquery.lazy.min.js"></script>

Lazy is even available through NPM and Bower. Just use one of the following commands below:

    $ npm install jquery-lazy
    $ bower install jquery-lazy

Basic Usage

The basic usage of Lazy ist pretty easy. Just prepare your elements and add a little snippet to your page.

Prepare the elements you want to lazy load. By default add a data-src attribute to elements containing the loadable image or a data-loader attribute to elements witch shall use custom loaders.

    <!-- load images the lazy way -->
    <img class="lazy" data-src="path/to/image.jpg" />

    <!-- load background images of other element types -->
    <div class="lazy" data-src="path/to/image.jpg"></div>

Start using Lazy by calling it after page load. Try to use a most exact jQuery selector as possible for better performance.

    $(function() {


Lazy comes with a bunch of easy to use configuration options by default, to control nearly every behavior as you like. The following parameters are available on every instance:

Name Type Default Description
chainable boolean true By default Lazy is chainable and will return all elements. If set to false Lazy will return the created plugin instance itself for further use.
autoDestroy boolean true Will automatically destroy the instance when no further elements are available to handle.
bind string load If set to load Lazy starts working directly after page load. If you want to use Lazy on own events set it to event.
threshold integer 500 Amount of pixels below the viewport, in which all images gets loaded before the user sees them.
visibleOnly boolean false Determine if only visible elements should be load.
appendScroll object window An element to listen on for scroll events, useful when images are stored in a container.
scrollDirection string both Determines the handles scroll direction. Possible values are both, vertical and horizontal.
defaultImage string blank image Base64 image string, set as default image source for every image without a predefined source attribute.
placeholder string null Base64 image string, set a background on every element as loading placeholder.
delay integer -1 If you want to load all elements at once after page load, then you can specify a delay time in milliseconds.
combined boolean false With this parameter, Lazy will combine the event driven and delayed element loading.
Name Type Default Description
attribute string data-src Name of the image tag attribute, where the image path is stored.
retinaAttribute string data-retina Name of the image tag attribute, where the path for optional retina image is stored.
loaderAttribute string data-loader Name or the element attribute, where the identifier of the customer loader is sored.
removeAttribute boolean true Determine if the attribute should be removed from the element after loading.
handledName string handled Name of the element tag data attribute, to determine if element is already handled.
Name Type Default Description
effect string show Function name of the effect you want to use to show the loaded images, like show or fadein.
effectTime integer 0 Time in milliseconds the effect should use to view the image.
Name Type Default Description
enableThrottle boolean true Throttle down the loading calls on scrolling event.
throttle integer 250 Time in milliseconds the throttle will use to limit the loading calls.
Name Type Default Description
beforeLoad function null Callback function, which will be called before the element gets loaded. Has current element as parameter.
afterLoad function null Callback function, which will be called after the element was loaded. Has current element as parameter.
onLoad function null Callback function, which will be called if the element could not be loaded. Has current element as parameter.
onFinishedAll function null Callback function, which will be called after all elements was loaded or returned an error. This callback has no parameter.

Configure your Lazy instances with an initial configuration object:

        // your configuration goes here
        scrollDirection: 'vertical',
        effect: 'fadeIn',
        visibleOnly: true,
        onError: function(element) {
            console.log('error loading ' + element.data('src'));


Or read and change the configuration live at runtime with the public config function. Please note the chainable parameter!

    var lazy = $('.lazy').lazy({ chainable: false });

    var attributeName = lazy.config('attribute');  // get
    lazy.config('effect', 'show');                 // set

Callbacks & Events

Lazy comes with a bunch of callbacks and events you can assign to. Just add them by initialization configuration to your instances

An list of all callbacks available by default:

Name Parameter Trigger
beforeLoad jQuery DOM element before an element is about to be handled
afterLoad jQuery DOM element after an element was handled successfully
onError jQuery DOM element whenever an element could not be handled
onFinishedAll none after all items in this instance was handled or returned an error

Simply attach a function to all callbacks you want to use by initialisation. The element parameter is already an jQuery object, so you can use it directly like element.addClass('handled').

        beforeLoad: function(element) {
            // called before an elements gets handled
        afterLoad: function(element) {
            // called after an element was successfully handled
        onError: function(element) {
            // called whenever an element could not be handled
        onFinishedAll: function() {
            // called once all elements was handled


this is the current Lazy instance itself, so you can access everything like public function or configuration directly.

        onFinishedAll: function() {
            if( !this.configuration.autoDestroy )

Public Functions & Instances

Lazy supports multiple parallel instances. Just initialize them with different jQuery selectors and possible different configurations.

An list of all available public functions:

Name Parameter Description
config {string} entryName[, {string} newValue] get or set an configuration entry
addItems {string|object} items add new items to current instance
getItems none get all unhandled items left of current instance
update [{boolean} useThrottle] loads all elements in current viewport
loadAll none loads all remaining available elements from this instance
destroy none unbinds all events and stop execution directly

To access an instances public functions you can initialize them in an object oriented manner or grab the instance bind to every element by default.

    // object oriented way, note the chainable parameter
    var instance = $('.lazy').Lazy({ chainable: false });

    // grab from elements
    // only works well if you use same selector or a single instance overall
    var instance = $('.lazy').data("plugin_lazy");


The public functions config and addItems has some multiple functionality.

    // 'config' can receive entries or set them to a new value
    var value = instance.config('attribute');
    instance.config('attribute', 'data-new-attribute');

    // 'addItems' works with an jQuery object or any selector
    // so these two lines have the exact same result

Custom Loaders

With the custom loaders option there is a powerful solution to load every contents the Lazy way. The plugin will handle everything, you just create a loading method witch got triggered whenever the element hits the visibility threshold. It's still possible to load images and custom loaders in the same Lazy instance.

To use a custom loader just define a name and function inside the Lazy initialisation. The first parameter is always a jQuery DOM object, representing the element you want to lazy load.

        customLoaderName: function(element) {
            element.html('element handled by "customLoaderName"');
        asyncLoader: function(element, response) {
            setTimeout(function() {
                element.html('element handled by "asyncLoader"');
            }, 1000);


Pass the loader name you want to use for this element to the data-loader attribute of those who should be lazy loaded. You can mix custom loaders and images in the same Lazy instance as well.

    <div class="lazy" data-loader="customLoaderName"></div>
    <img class="lazy" data-src="path/to/image.jpg" />
    <div class="lazy" data-loader="customLoaderName"></div>
    <div class="lazy" data-loader="asyncLoader"></div>

Custom loaders can respond it's state back to the plugin. This is highly necessary when you want to use one of the callbacks afterLoad, onError or onFinishedAll beside of your loaders.

Therefor you can either use jQuerys' build-in functions load and error, or the response function, given as second parameter to your custom loaders. Both ways do exactly the same, so you only had to choose one of them.

    // jQuerys' build-in functions
        successLoader: function(element) {
        errorLoader: function(element) {

    // response callback function
        successLoader: function(element, response) {
        errorLoader: function(element, response) {


This plugin is made by Daniel 'Eisbehr' Kern and is 100% FREE under MIT and / or GPL-2.0 license.

If you are feeling generous and want to show your support, you can buy me a beer or coffee via the PayPal donate button below. :)


I hope you find this plugin useful.
Feel free to get in touch if you have any questions or suggestions.


Want to get in contact with me?

You can join me and the project on GitHub or use the Comments below. Please report bugs only on GitHub, just create an issue there.

I'll appreciate your support!