Created
November 13, 2012 01:47
-
-
Save yasuoza/4063368 to your computer and use it in GitHub Desktop.
Web site with retina display
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
<!DOCTYPE html> | |
<head> | |
<script src="js/dynamic_retina.js"></script> | |
</head> | |
<body> | |
<img src="img/google.png" style="width:138px;height:48"> | |
</body> | |
</html> |
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
RetinaImageConverter = { | |
resize_images: => | |
return unless @devicePixelRatio? and @devicePixelRatio >= 1.5 | |
images = document.getElementsByTagName("img") | |
for image in images | |
image.src = image.src.replace(/\.\w+$/, (match) -> "@2x#{match}") | |
} | |
@onload = RetinaImageConverter.resize_images |
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
(function() { | |
var RetinaImageConverter = { | |
resize_images: function() { | |
if ((this.devicePixelRatio == null) || this.devicePixelRatio < 1.5) { | |
return; | |
} | |
var images = document.getElementsByTagName("img"); | |
for (var i = 0, len = images.length; i < len; i++) { | |
images[i].src = images[i].src.replace(/\.\w+$/, function(match) { return "@2x" + match }); | |
} | |
} | |
}; | |
this.onload = RetinaImageConverter.resize_images; | |
}).call(this); |
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
<!DOCTYPE html> | |
<head> | |
<!-- Using retina.js http://retinajs.com/ --> | |
<script src="js/retina.js"></script> | |
</head> | |
<body> | |
<img src="img/google.png" style="width:138px;height:48"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Support retina display
Candidate
Use dynamic image src changing
When document loaded, replace image src with @2x prefix.
apple.com based on this.
dynamic_retina.coffee:
dyanmic_retina.js:
Merit
Fast @2x image loading
Demerit
You need to prepare all @2x image.
You cannot use images which there is not @2x version.
Use retina.js
Make XMLHttpRequest to server to verify there is @2x image.
When there is @2x image, replace image src with @2x prefix, otherwise not.
In your html file. Load
retina.js
Merit
You can use images which there is not @2x version.
So, you do not have to prepare all @2x images.
Demerit
Use server side retina support(Rails)
Store client resolution to session, and use it.
In rails
clear_eyes
gem supplies retina image tag (a.k.ar_image_tag
).In your Gemfile:
In application.js
In your view file
Merit
Do not dependent on client browser power.
Demerit
Use server power.