Created
October 7, 2012 16:30
-
-
Save dtorres/3848834 to your computer and use it in GitHub Desktop.
This gist allows you to serve proper images according to the resolution of the window.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Server side check if there is a cookie that defines | |
devicePixelRatio, if not, serve this javascript */ | |
//Does it support it? no, default to 1; | |
if (window.devicePixelRatio === undefined) { | |
window.devicePixelRatio = 1; | |
} | |
//Setup cookie date. | |
var now = new Date(); | |
var time = now.getTime(); | |
time += 10*24*365*3600 * 1000; //10 Years | |
now.setTime(time); | |
//Set the cookie | |
document.cookie = "devicePixelRatio="+window.devicePixelRatio+";path=/;expires="+now.toGMTString(); | |
//Reload the page | |
window.location.reload(); | |
/* Now you can use this cookie value to serve proper images | |
to that device and avoid using more bandwidth */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment