Right now I am using this function:
function is_retina_device() { return window.devicePixelRatio > 1; }
But its simplicity scares me
devicePixelRatio is not reliable at all. when you zoom in to 200%, the window.devicePixelRatio will return you 2, but you are not on a retina display.