Skip to content

Instantly share code, notes, and snippets.

@charliepark
Created February 24, 2015 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charliepark/65223d218602f67a88db to your computer and use it in GitHub Desktop.
Save charliepark/65223d218602f67a88db to your computer and use it in GitHub Desktop.
performantRetina.js
var performantRetina = {
run : function(){
if(!window.devicePixelRatio || window.devicePixelRatio === 1){return;}
var images = document.getElementsByTagName('img');
for(var i = 0; i < images.length; i++){
var retinaSrc = images[i].getAttribute('data-retina-src');
if(!retinaSrc){continue;}
images[i].setAttribute('src', retinaSrc);
}
}
};
performantRetina.run();
// Why bother with this? Only benefit would be if downloading images were blocking in some way, so downloading initial image would download and be done, other processes could run, and then subsequent image could download. Don't have time to test it out right now, but I suspect we're better off just using srcset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment