Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

## How it works

There are 4 ways to use `retina.js`:
There are 5 ways to use `retina.js`:

1. Automatically swapping out `src` paths on `img` tags.
2. Automatically swapping out background image URLs in inline styles.
3. Manually specifying the location of a high-res image variant (works for `src` attributes and inline styles).
4. Automatically creating media queries for CSS background images.
5. [new feature - 20200315 added]only load image once for elememnts that have attribute: `data-rjs-src` and `src` is empty

#### Img Tags

Expand All @@ -25,7 +26,7 @@ With this in mind, you'll specify your highest environment level with the `data-
Let's say you have an image on your page that looks like this:

```html
<img src="/images/my_image.png" data-rjs="3" />
<img src="/images/my_image.png" data-rjs="3" />~~~~~~~~
```

In this case, we've set our resolution cap at "3", denoting that we've prepared 3x and 2x image variants. When the page loads, `retina.js` will check the actual resolution of the device environment to decide whether it should really serve up a 3x image. If the user happens to be in a 2x environment, `retina.js` will serve up the 2x image instead, assuming it will find the image at `/images/my_image@2x.png`.
Expand Down
8 changes: 8 additions & 0 deletions dist/retina.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/retina.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/retina.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/retina.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ function dynamicSwapImage(image, src, rjs = 1) {
if (src && cap > 1) {
const newSrc: string = src.replace(srcReplace, `@${cap}x$1`);
setSourceIfAvailable(image, newSrc);
} else if (!src) {
const realSrc = image.getAttribute('data-rjs-src');
if (cap > 1) {
const newSrc: string = realSrc.replace(srcReplace, `@${cap}x$1`);
setSourceIfAvailable(image, newSrc);
} else {
setSourceIfAvailable(image, realSrc);
}
}
}

Expand Down
Loading