Get new jQuery plugins just once a week



September 13, 2015

Smarter-Images | jQuery plugin for simple responsive images

Smarter-Images is an extremely easy to use jQuery plugin for responsive images using an external service.

Created by Mike Zarandona



Smarter-Images plugin

responsive images


Images are dumb - make them smarter with flexible dynamic image replacement

Demo on


SmarterImages aims to be the most flexible dynamic image replacement jQuery plugin. Think CDN, but without the server.

The plugin watches the browser viewport width on load() and resize(), and when the zone changes the plugin rebuilds a new src URL. If the object in question is an <img/> element, it gets a new src; if the object in question is anything else (such as a <div/>) it will get an updated background-image style property.


Inline Images and Placeholder.gif

To fire SmarterImages on inline <img/> elements, they are required to have both an src attribute and a data-si-src attribute. Even though the "real" src is stored inside data-si-src, without a "true" src the image won't load correctly. To get around this, the fastest-known solution named placeholder.gif is included - a 43byte 1px x 1px transparent GIF, more on that here. Please note that in some cases it's more appropriate for user experience to implement a "loading" graphic, like a nice FontAwesome animated icon.

Definitions: Breakpoints vs. Zones

This document will refer to terms such as "breakpoint" and "zone" - here's what they mean:

A pixel integer value at which the script will initiate an image swap. These markers encapsulate the zones. They're defined by passing in an array of integers to options.breakpoints.

The range in which a breakpoint-specific sized image is visible. These are the areas between the breakpoints, and are automatically calculated.

0       360         480         768         1050        1300        1600

        0 (min)            1           2           3           4        5 (max)


Processors are any services, CDNs, APIs, or custom functions which handle image sizing and/or serving. Additional options for processors are always welcome and appreciated, please open an issue with suggestions!

<> is the easiest way to resize, store, and deliver your images to your customers.     —

To use (paid service) set options.useCloudImageIO to true, and pass in your URL prefix to options.cloudImageIO. That's it!

Custom Processor

To use any other custom setup, set options.useCustomURL to true and pass in a custom URL to options.customURL. Two replacement variables are available to help build the correct URL - check out the code examples section later in this document.

Custom Processor URL Replacement Variables

%%size%% This string will be replaced with the current breakpoint size dynamically.

Example: Output:

%%source%% This string will be replaced with the current image's source attribute (data-si-src).

Example: Output:


To use placeholders for mock-ups or testing purposes (for science), set options.usePlaceholders to true. Note that this will ignore the data-si-src option completely and will populate the targeted object(s) with placeholder images served from


Option Type Default Description
breakpoints array [360, 480, 768, 1050, 1300, 1600] Defines the breakpoints at which targeted images will be replaced.
upsizeOnly boolean false If true, images will only load larger sizes to reduce server calls; if false, images with load larger and smaller sizes.
maintainAspect boolean false If true, images will maintain their original width / height aspect ratio.
useCloudImageIO boolean false Switch to turn on / off the image processor.
cloudImageIO string N/A URL account prefix.
useCustomURL boolean false Switch to turn on / off the custom URL image processor.
customURL string N/A Custom image processor URL pattern.
usePlaceholders boolean false Turn on placeholder images for testing.
protocol string http:// Defines the protocol for the target image URLs (http://, https://, //).
logging boolean false Turns on / off console messages for debugging / testing.
onImgSwap function false Callback function which fires after each replacement.


Basic Examples

Inline Image

<!-- HTML -->
<img src="/path/to/placeholder.gif" data-si-src=""></div>
// jQuery
// when the document is ready
$(document).ready(function() {

    // call SmarterImages

Background Image

<!-- HTML -->
<div class="smarter-image" data-si-src=""></div>
// jQuery
$('.smarter-image').smarterImages(); Example

// jQuery
    useCloudImageIO: true,
    cloudImageIO: 'abcdef'

Custom URL Example

// jQuery
    useCustomURL: true,
    customURL: ''

Callback Function Example

$this is exposed so that each <img/> can be targeted individually.

thisBreakpoint holds the current zone's size, in pixels.

// jQuery
    useCloudImageIO: true,
    cloudImageIO: 'abcdef',

    onImgSwap: function($this, thisBreakpoint) {
        // your callback function code here
        // ...

Kitchen Sink Example

        // basic things
        breakpoints: [360, 480, 768, 1050, 1300, 1600],
        upsizeOnly: true,
        maintainAspect: false,

        // setup
        useCloudImageIO: false,
        cloudImageIO: '',

        // custom url setup
        useCustomURL: false,
        customURL: '',

        // placeholders (for science)
        usePlaceholders: false,

        // nuts + bolts
        protocol: 'http://',
        logging: false,

        // callback function
        onImgSwap: function($this, thisBreakpoint) {
            // ...



Initial release.


Mike Zarandona |


Related posts:

Responsive slides
Smarter-Images plugin

jQuery plugin

Sign up for our weekly newsletter.

* We won't spam you ever
Couple Gift Ideas