A new twist on the old school LOWSRC IMG attribute, which would render a lower file size image first while a larger file size image would appears in its place later.

Back to the future, we set in the markup and leave the lower file size image.

However, if the HiSRC plugin detects fast network or high resolution, then a high resolution image takes the image’s place.

HiSRC Image (resize browser window)

Regular image

How It Works

The browser loads the low-resolution image first with an old-fashion IMG SRC attribute.

Then the HiSRC jQuery plugin checks the resolution of the browser.

If the browser resolution is wider than the default 640 pixels width, then the plugin overwrites the low-resolution image for the higher resolution image.

However, if mobile bandwidth is detected (like 3G), the low-resolutions stay in place.

Setting Up

Associate jQuery to your web document as well as the HiSRC plugin as well.

In this code example, jQuery is link to Google’s CDN and the HiSRC plugin is in the same directory as the web document:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script src="hisrc.js"></script>

Use basic jQuery to pick out which images should be HiSRC’d:

 $(".hisrc img").hisrc();
 $(".hisrc img+img").hisrc({ minwidth: 800 });

The high-resolution image links should be placed as the value of data-hisrc in the markup of your web page:

<h3>HiSRC Images</h3> (resize browser window)
 <div class="hisrc">
 <img src="http://placehold.it/400x200.png" data-hisrc="http://placehold.it/640x200.png">
 <img src="http://placehold.it/400x200.png" data-hisrc="http://placehold.it/800x200.png">

<h2>Regular images</h2>
 <img src="http://placehold.it/400x200.png">
 <img src="http://placehold.it/400x200.png">