Skip to Main Content

retina.js is an open source script that makes it easy to automatically serve high-resolution images to devices with retina displays.

How it works

When your users load a page, retina.js checks each image on the page to see if there is a high-resolution version of that image on your server. If a high-resolution variant exists, the script will swap in that image in-place.

The script assumes you use Apple’s prescribed high-resolution modifier (@2x) to denote high-resolution image variants on your server.

For example, if you have an image on your page that looks like this:

<img src="//jdmdigital-204e1.kxcdn.com/images/my_image.png" />

The script will check your server to see if an alternative image exists at this path:

"//jdmdigital-204e1.kxcdn.com/images/my_image@2x.png"

So, you just have to make sure an image at exactly twice the pixel dimensions exists at that location with the file naming convention, image.png -to- image@2x.png.

How to use it

The JavaScript helper script automatically replaces images on your page with high-resolution variants (if they exist). To use it, download the script and include it at the bottom of your page.

  1. Place the retina.js file on your server
  2. Include the script on your page<script type="text/javascript" src="//jdmdigital-204e1.kxcdn.com/scripts/retina.js"></script>
    (put it at the bottom of your template, before your closing </body> tag)
  3. Create BOTH images (normal size and 2-times) named according to image.jpg & image@2x.jpg.
  4. That’s it!

Download Retina.js from Github.

Share the love:

Discussion

Comments are now closed.

Get the Email

Join 1000+ other subscribers. Only 1 digest email per month. We'll never share your address. Unsubscribe anytime. It won't hurt our feelings (much).

Preview Email