Skip to content

Instantly share code, notes, and snippets.

@drewwells
Created December 5, 2012 22:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewwells/4219907 to your computer and use it in GitHub Desktop.
Save drewwells/4219907 to your computer and use it in GitHub Desktop.
Webkit+Moz detect device pixel ratio
var ratio = window.devicePixelRatio ||
(function(i){
var wmq = window.matchMedia;
while( !window.devicePixelRatio && i > 0 &&
!wmq("(min--moz-device-pixel-ratio:" + i/10 + ")").matches ){
i=i-1;
}
return i/10;
})(30);
@objectivehtml
Copy link

I just searched google for this code and this appears to be exactly what I was looking for. How reliable is this? I am working on a cross-browser solution to serve retina icons for Google Maps.

Would this work on Firefox too? Obviously I will test this too, just wanted to get your feedback.

if(ratio > 1.5) {
    console.log('serve high res graphics');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment