Skip to content


add an option to choose the path suffix for 2x images #58

wants to merge 2 commits into from

7 participants


Added an option to choose the path suffix for 2x images.

I'm using _2x path suffix for my retina images, just as does. But this script only works if your retina image suffix is "@2x". So I added an option.

Commit e7930be
Added another option to select just some of the img tags to make their image retina, not all the images on a webpage.
I can see "travis build failed", because of querySelectorAll. Maybe travis is using an old JS engine.


I think adding retinaImageSuffix is a good idea (1304e63), though it would be nice if these two changes were separate pull request.

Related to retinaImgTagSelector (e7930be), see #46.

@YuAo YuAo closed this

This would help us out a great deal if this was accepted.


Has there been decision on this yet? Trying to reduce wasted HTTP calls.

any plan to merge this?

this would be great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 8 additions and 2 deletions.
  1. +8 −2 src/retina.js
10 src/retina.js
@@ -3,6 +3,12 @@
var root = (typeof exports == 'undefined' ? window : exports);
var config = {
+ // An option to choose a suffix for 2x images
+ retinaImageSuffix : "@2x",
+ // An option to select some of the img tags to make their image retina.
+ retinaImgTagSelector : "body img",
// Ensure Content-Type is an image before trying to load @2x image
check_mime_type: true
@@ -25,7 +31,7 @@
var existing_onload = context.onload || new Function;
context.onload = function() {
- var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
+ var images = document.querySelectorAll(config.retinaImgTagSelector), retinaImages = [], i, image;
for (i = 0; i < images.length; i++) {
image = images[i];
retinaImages.push(new RetinaImage(image));
@@ -54,7 +60,7 @@
function RetinaImagePath(path) {
this.path = path;
- this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
+ this.at_2x_path = path.replace(/\.\w+$/, function(match) { return config.retinaImageSuffix + match; });
RetinaImagePath.confirmed_paths = [];
Something went wrong with that request. Please try again.