Retina.js

retina.js
Retina.js

RetinaJS allows you to serve up a smaller, low-fi image by default to your users before swapping in a larger retina image for users that will enjoy the sharper crisper graphics.

The obvious issue with this approach is that you will get a double download for anyone using a up-market smart phone (galaxy, iphone 4s<) and usually it’s the mobile devices you want to limit the number of http requests.

Still this is a great solution if you’ve got rasterized images, however for icons we would suggest looking at using SVG’s to accomplish and much neater solution.

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="/images/my_image.png" />

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

"/images/[email protected]"

See the Pen RWD.is example: Retina.js by Justin Avery (@justincavery) on CodePen


  • Resource Name

    Retina.js

  • Resource Creator

    Imulus

Description

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.

View on Github Download Resource

Sites that use Retina.js

Subscribe to our Newsletter

Add your email address and receive an email every Friday covering off everything worth knowing about building your websites responsively.