Giter Site home page Giter Site logo

strues / retinajs Goto Github PK

View Code? Open in Web Editor NEW
4.4K 127.0 619.0 2.66 MB

JavaScript, SCSS, Sass, Less, and Stylus helpers for rendering high-resolution image variants

Home Page: http://retinajs.com

License: MIT License

JavaScript 49.14% CSS 50.86%
retina javascript image dpi

retinajs's Introduction

retina.js

npm version styled with prettier Commitizen friendly GitHub license

JavaScript, Sass, Less, and Stylus helpers for rendering high-resolution image variants

retina.js makes it easy to serve high-resolution images to devices with displays that support them. You can prepare images for as many levels of pixel density as you want and let retina.js dynamically serve the right image to the user.

How it works

There are 4 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.

Img Tags

retina.js assumes you are using Apple's prescribed high-resolution modifiers (@2x, @3x, etc) to denote high-res image variants on your server. It also assumes that if you have prepared a variant for a given high-res environment, that you have also prepared variants for each environment below it. For example, if you have prepared 3x variants, retina.js will assume that you have also prepared 2x variants.

With this in mind, you'll specify your highest environment level with the data-rjs attribute and let retina.js take it from there.

Let's say you have an image on your page that looks like this:

<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/[email protected].

If the environment does have 3x capabilities, retina.js will serve up the 3x image. It will expect that url to be /images/[email protected]. If the environment has the ability to display images at higher densities than 3x, retina.js will serve up the image of the highest resolution that you've provided, in this case 3x.

Inline Styles

Previous versions of retina.js were unable to target background images set via inline styles. Now, if you apply a data-rjs attribute to any kind of element other than an img, the script will target inline background images instead of src attributes.

So if you created an element like this:

<div style="background: url(/images/my_image.png)" data-rjs="3"></div>

retina.js would convert it to something like this:

<div style="background: url(/images/[email protected])" data-rjs="3"></div>

The logic behind image swapping is exactly the same when dealing with background images as it is when dealing with src attributes. If the user's environment only supports 2x variants, retina.js will load the 2x variant instead of the 3x.

Note that it is up to you in a case like this to correctly apply background sizing and any other necessary background-related styles to the element. retina.js will not affect these.

Manually Specifying a High-Res URL

In previous versions, you could tell the script where to find your high-res file by using the data-at2x attribute. Now, if you pass a URL to the data-rjs attribute, retina.js will use the image at the path you specify for all high-resolution environments instead of trying to dynamically serve an auto-suffixed image path based on the environment's capabilities. This will work for both src attributes on img tags and inline background images on all other tags.

For example, you might write something like this:

<img
  src="/images/my_image.png"
  data-rjs="/images/2x/my-image.png" />

<!-- or -->

<div
  style="background: url(/images/my_image.png)"
  data-rjs="/images/2x/my-image.png">
</div>

If the user then loads the page in any kind of high-resolution environment, they'll get the following:

<img
  src="/images/2x/my-image.png"
  data-rjs="/images/2x/my-image.png" />

<!-- or -->

<div
  style="background: url(/images/2x/my-image.png)"
  data-rjs="/images/2x/my-image.png">
</div>

Media Queries

retina.js comes with mixins for SCSS, Sass, Less, and Stylus. These mixins work similarly to the JavaScript version in that they will dynamically serve images for as many high-res environments as you've prepared image variants for. Previously, these mixins were named "at2x" but because they now serve images for multiple environments, they have been renamed "retina".

In each language, the retina mixin allows 4 parameters:

  1. path - The path to your standard resolution image.
  2. cap - Optional. The highest resolution level for which you have prepared images. Defaults to 2.
  3. size- Optional. A value to be applied to the background-size property. Defaults to auto auto.
  4. extras- Optional. Any other values to be added to the background property. Defaults to nothing.

Here is an example wherein we are specifying that we have prepared images for both 2x and 3x environments:

SCSS

#item {
  @include retina('/images/my_image.png', 3, cover, center center no-repeat);
}

Sass

#item
  +retina('/images/my_image.png', 3, cover, center center no-repeat)

Less

#item {
  .retina('/images/my_image.png', 3, cover, center center no-repeat);
}

Stylus

#item
  retina('/images/my_image.png', 3, cover, center center no-repeat)

Regardless of the dialect, the output is effectively the same:

#item {
  background: url("/images/my_image.png") center center no-repeat;
  background-size: cover;
}

@media all and (-webkit-min-device-pixel-ratio: 1.5),
       all and (-o-min-device-pixel-ratio: 3 / 2),
       all and (min--moz-device-pixel-ratio: 1.5),
       all and (min-device-pixel-ratio: 1.5) {
  #item {
    background: url("/images/[email protected]") center center no-repeat;
    background-size: cover;
  }
}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  #item {
    background: url("/images/[email protected]") center center no-repeat;
    background-size: cover;
  }
}

@media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 288dpi) {
  #item {
    background: url("/images/[email protected]") center center no-repeat;
    background-size: cover;
  }
}

Compatibility

retina.js is compatible with all modern browsers and should not throw errors in old browsers all the way back through IE6.

Installing & Launching

JavaScript

There are 2 ways to use the JavaScript version of retina.js:

  1. The old-school way (manually dropping the script into an html file).
  2. The new-school way (importing it into a larger JavaScript build process).

Old-School

To use retina.js the old-school way, download retina.min.js and put it on your server. Then, include the script in your html file at the bottom of your template, before your closing </body> tag.

<script type="text/javascript" src="/scripts/retina.min.js"></script>

Using this technique, retina.js will run automatically on page load. It will also create a globally available function called retinajs. Whenever you'd like to manually re-initialize the script, simply call window.retinajs().

If you don't pass any arguments to the retinajs function, it will only attempt to process images that have not previously been processed by the script. Optionally, you can pass a collection of HTML elements to the script, in which case it will only attempt to process elements in that collection, specifically the ones that have not been processed before. Your collection may take the form of an Array, NodeList, or jQuery selection.

retinajs();
// Finds all images not previously processed and processes them.

retinajs( [img, img, img] );
// Only attempts to process the images in the collection.

retinajs( $('img') );
// Same.

retinajs( document.querySelectorAll('img') );
// Same.

New-School

To use retina.js the new-school way, you'll want to require it (or import it if you're using ES6) into your Gulp/Webpack/Grunt/CommonJS/etc application. In this case, the script won't run automatically. Instead, it'll let you determine when you'd like it to run.

import retina from 'retina';

window.addEventListener('load', retina);

Notice that the retina function can be called as often as you need in order to re-initialize the image swapping.

If you don't pass any arguments to the retina function, it will only attempt to process images that have not previously been processed by the script. Optionally, you can pass a collection of HTML elements to the script, in which case it will only attempt to process elements in that collection, specifically the ones that have not been processed before. Your collection may take the form of an Array, NodeList, or jQuery selection.

retina();
// Finds all images not previously processed and processes them.

retina( [img, img, img] );
// Only attempts to process the images in the collection.

retina( $('img') );
// Same.

retina( document.querySelectorAll('img') );
// Same.

CSS Preprocessors

The process for including the CSS mixins is relatively straightforward. Here is a breakdown for each:

SCSS

Add the @mixin retina( ... ) mixin from _retina.scss to your SCSS stylesheet (or reference it in an @import). In your stylesheet, call the mixin using @include retina( ... ) anywhere instead of using background or background-image.

Sass

Add the =retina( ... ) mixin from _retina.sass to your Sass stylesheet (or reference it in an @import). In your stylesheet, call the mixin using +retina( ... ) anywhere instead of using background or background-image.

Less

Add the .retina( ... ) mixin from retina.less to your Less stylesheet (or reference it in an @import). In your stylesheet, call the mixin using .retina( ... ) anywhere instead of using background or background-image.

Stylus

Add the retina( ... ) mixin from retina.styl to your Stylus stylesheet (or reference it in an @import). In your stylesheet, call the mixin using retina( ... ) anywhere instead of using background or background-image.

Considerations for Ruby on Rails 3+

...or any framework that embeds some digest/hash to the asset URLs based on the contents, e.g. /images/image-{hash1}.jpg.

The problem with this is that the high-resolution version would have a different hash, and would not conform to the usual pattern, i.e. /images/image@2x-{hash2}.jpg. So automatic detection would fail because retina.js would check the existence of /images/image-{hash1}@2x.jpg.

There's no way for retina.js to know beforehand what the high-resolution image's hash would be without some sort of help from the server side. So in this case, there are a couple of options for handling it:

Bypass Digesting

One potential method is to bypass digesting altogether by implementing a process like team-umlaut's asset compile rake file which will generate non-digested asset files as necessary.

Use Manual Paths

Although it's not quite as fancy as dynamically serving up files based on the resolution of the user's environment, this may be a good time to pass a URL string to the data-rjs attribute so that you can manually tell retina.js exactly where to look for a high-resolution variant of your image.

retinajs's People

Contributors

adammerrifield avatar aliaghdam avatar benatkin avatar brchristian avatar caseyohara avatar cmoen avatar coyote240 avatar e1ven avatar eliasnawfal avatar feelepxyz avatar fernandezpablo85 avatar henrikjoreteg avatar honpery avatar jbinney avatar jgnewman avatar jvannistelrooy avatar kathiekiwi avatar michelv avatar nathancrank avatar robertzk avatar robflaherty avatar ronny avatar severeoverfl0w avatar taylorsmith avatar uudens avatar wiedikerli avatar wub avatar xyu avatar yuao avatar zackdever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

retinajs's Issues

Support Bower

Bower is a package manager for the web from Twitter.

Add component.json to project:

{
  "name": "retina",
  "version": "0.0.2",
  "main": "./retina.js"
}

bower register retina git://github.com/imulus/retinajs.git

Using window.onload wipes out any other onload handler previously set by non-retinajs code

retina.js is included as the last thing in the body of the html document, and since it sets a window.onload handler when running in a browser with a retina display, it'll overwrite any existing onload handler set by code that ran earlier.

This is causing me issues since I have javascript code that I'd like to run onload. In my case, I'd like to asynchronously load a google map (see https://developers.google.com/maps/documentation/javascript/tutorial#asynch).

Obviously there are workarounds for this, and that's what I'll use in the meantime, but it would be nice if retina.js didn't overwrite the onload handler.

There are some blog posts out there about alternatives to just blowing away existing onload handlers. See:

http://haacked.com/archive/2006/04/06/StopTheWindow.OnloadMadness.aspx
http://www.dannytalk.com/how-to-handle-multiple-window-events-in-javascript/

Fails with status "0" when serving the files locally

Hi,

I'm using retina.js in an iOS application. This application is using UIWebView to show locally stored HTML/PNG files. Both the HTML file and the corresponding PNG files are placed inside my application bundle. The HTML is displayed correctly with 1x images, but the script fails to replace them with 2x images for the new iPad (Retina). Debugging the script shows that b.status is returned as "0".

I'm sure that a lot of people would like to use this script with UIWebView and local HTML/PNG files. So, a solution to this problem would be highly appreciated.

Regards,
Mustafa

Not working in Rails 3.2.8 Production

Once Rails 3.2.8 asset pipeline precompiles/minifies Retina.js 0.0.2 and combines it with my other JS files into application.js, Retina.js no longer fires. It works perfectly in development.

404 Errors in Chrome console

We own a site where users can upload their own pictures which are most likely not in a retina resolution. The problem is, that retina.js throws a 404 for every @2x image which can't be found.

Is there no way to prevent the js from throwing 404s?

Broken on servers with mod_pagespeed enabled

mod_pagespeed seems to break this script because it also rewrites the url, apparently last.

It could be something on my end, but I don't know enough about either mod_pagespeed, or js to really know. I'll be looking into it though.

doesn't work in offline mode?

Added the js file and all image files (both retina and non-retina) into the appcache manifest, but in offline mode no replacement occurs. Not sure if this is a bug. Does retinajs require internet connection to work? Thanks

@at2x_path not working in LESS mixin

I have been trying to work out why the @2x version file is not being loaded. I have done several limited tests on my end the only way I know how.

If I enter the exact path of the @2x version ([email protected]) in the variable @at2x_path in the mixin it works, so to me that shows that the mixin is working, just not the variable.

I am using the latest release of LESS and testing on iPad3.

Doesn't work with AJAX loaded content

When a content is loaded with AJAX the script doesn't activate. You can see it in action here (it's my company site, no advertising intended): http://nikolaydyankovdesign.com/

The small black & white images on the homepage have retina versions, I checked the filenames. In the inner pages where the content is static it works fine.

I understand it can't know when a content is loaded, but a hook for refreshing the script would work just fine.

Great job with this script, keep it up!

Doesn't work for dynamically inserted images?

I tried to use retina.js inside a one page js app, the DOM is dynamically generated with JS template.
But it looks like it's not working.
Does retina.js works only on static pages?
Thanks in advance,

Best regards,
Sam

syntax issue in less mixin implementation

the provided less mixin breaks the less compiler and spits out css that does not load

This line creates an error:
background-image: url(@path);

.at2x(@path, @w: auto, @h: auto) {
background-image: url(@path);
@at2x_path: ~"@{path}".split('.').slice(0, "@{path}".split('.').length - 1).join(".") + "@2x" + "." + "@{path}".split('.')["@{path}".split('.').length - 1];

@media all and (-webkit-min-device-pixel-ratio : 1.5) {
background-image: url(@at2x_path);
background-size: @w @h;
}
}

body{
.at2x('site-graphics/leather-bg.jpg',500px,465px);
}

moving the 'url()' into the variable fixes the problem:

.at2x(@path, @w: auto, @h: auto) {
background-image: @path;
@at2x_path: ~"@{path}".split('.').slice(0, "@{path}".split('.').length - 1).join(".") + "@2x" + "." + "@{path}".split('.')["@{path}".split('.').length - 1];

@media all and (-webkit-min-device-pixel-ratio : 1.5) {
background-image: @at2x_path;
background-size: @w @h;
}
}

body{
.at2x(url('site-graphics/leather-bg.jpg'),500px,465px);
}

Retina.js does not work at all

I've tested it on a server after experiencing it not working on localhost, I get no errors whatsoever. Nothing just happens

Trigger Image Change on click (testing!)

Hello! I'd love to be able to test the swapping of the retina images for testing. I'm not JS wizard though. This doesn't work, but is three something similar I could do?

$('.toggle-retina').click(function() {
Retina.init(root);
});

Test out requestAnimationFrame performance

Hi Guys,

This might be a hair brained idea... and just a knee jerk issue post... But I wonder how requestAnimationFrame compares to setTimeout with the task you are performing?

Disclaimer: I don't know too much on the subject.

Alex MacCaw
@maccman
"I'm deferring any async rendering needed to requestAnimationFrame - it's so much faster. https://developer.mozilla.org/en/DOM/window.requestAnimationFrame"
Source: https://twitter.com/#!/maccman/status/190244937793671168

Also the pollyfill: "requestAnimationFrame for smart animating"
http://paulirish.com/2011/requestanimationframe-for-smart-animating/

CSS3 transitions

Hey guys,

Just noticed that if you're using something similar to the following in your stylesheets the @2x image won't fire:

body, h1, a, img, input { transition:all .4s linear; -o-transition:all .4s linear; -moz-transition:all .4s linear; -webkit-transition:all .4s linear; }

Any ideas on why this happens? I'm assuming it's to do with the reference to img in the line above..

Issues with Genesis Responsive Slider in Wordpress

I am attempting to implement retina.js on a Wordpress site and everything works great with the exception of the Genesis Responsive Slider. When on a retina display it loads the first image in the slider and then the slider disappears entirely for each subsequent image until it comes back around to the first one. Any ideas?

Maybe don't wait for onload?

Is there a reason we have to wait for the onload event to check for the 2x files? Couldn't we kick off the ajax requests as soon as we have the filenames instead of waiting for all the images to download?

Causes problems with responsive layout

On my website I have images scale appropriately to the dimensions of the window. This results in a different image width on the iPad in portrait vs. landscape orientation. If I load a page up in landscape orientation and rotate, after retina.js does its thing it looks great. If I load the page up in portrait orientation and rotate, after retina.js does its thing the images remain the same size they were in portrait.

I presume this is because the script looks up the image dimensions with offsetWidth and offsetHeight. Is there any way to avoid this problem?

Retina.js puts @2x to all images, no matter if the @2x file is found on the server

I ran into a strange issue while implementing retina js.
On my local server environment everything works fine. When i deploy it to the server the script adds @2x at the end of each image name, no matter if the @2x image exists on the server. So in result i get a website which shows only retina images, although the non-retina aren't showing. Any clue what might be the problem here?

Add image link support

It would be awesome to be able to use retina.js in combination of lightbox scripts. At the moment this is not possible, because retina.js only affects images themself. The image opened in the dialog should be a nice retina image as well :)

add option to specify which images with a selector

We have set up retina images for two key images on a mobile site - the logo and a contact number graphic.

The client hosts their own website has been enquiring why their logs are filling up with not found errors for all the other retina graphics that the script is checking for.

It seems it would be quite simple to add in an option to do this, by changing this line:

document.getElementsByTagName("img")

to

document.getElementsByClassName(“retina”)

obviously not entirely this simple as you would need to wrap it up into an option but not a major rewrite.

Check if <img> has width and height attributes before setting them

If images are invisible on the page retina.js will give the replaced versions the dimensions of 0x0.
Fixed it like this:

if (t.el.complete) {
if (parseInt(t.el.getAttribute("width"), 10) > 0) {
t.el.setAttribute("width", t.el.getAttribute("width"));
} else {
t.el.setAttribute("width", t.el.offsetWidth);
}
if (parseInt(t.el.getAttribute("height"), 10) > 0) {
t.el.setAttribute("height", t.el.getAttribute("height"));
} else {
t.el.setAttribute("height", t.el.offsetHeight);
}
t.el.setAttribute("src", e);
} else {
setTimeout(n, 5);
}

Sometimes Doesn't Load @2x Images

I am having an issue where sometimes the retina images aren't being loaded. It shows a blue question mark; as if the image could not be loaded.

This is only happening periodically and if I reload the page a couple of times, this retina image will finally load properly.

Any suggestions?

Image part of a form element

Just added to retinajs to our site and started to go through and add high resolution versions of all images. All works fine so far except for one image. I found it was part of a form element:

< input type="image" src="order_now.png" width="290" height="53" name="order_now" value="Order now" >

Should this be working already, or can you add support for this type of image tag?

<img> with CSS border - Wrong dimensions

Guys, I can't fucking believe you didn't notice that if an image has a border defined in CSS, retina.js will increase the image size adding by border size.

So if the image has 100x100px and border 3px, the final size after-retina.js is 103px x 103px and that sucks.

Solution:
Replace
that.el.setAttribute('width', that.el.offsetWidth);
that.el.setAttribute('height', that.el.offsetHeight);

With:
that.el.setAttribute('width', that.el.width);
that.el.setAttribute('height', that.el.height);

Retina.LESS Doesn't Compile

Hey,

Using the newest version of retina.less does not compile. If I go back to before the extra browsers where added it compiles fine (#13).

Error

ParseError: Syntax Error on line 8 in retina.less:2:5
1 // retina.less
2 // A helper mixin for applying high-resolution background images (http://www.retinajs.com)
3 

This is using the lessc bundler included in the newest repo version.

Oops...

Looks like my issue has already been discussed, for some reason I didn't find this post before I submitted my own:

#8

Exclude Mobile Devices?

First post on GitHub ever, go easy on me. Is there any easy way to include support for iPads, Macs and larger devices, while EXCLUDING small mobile devices like phones? I have a photography website, and my @2x files are huge. Everything is already high enough resolution for smaller screens. I'd love to avoid the bandwidth strain on small devices, which are likely the site visiting on a cell connection rather than WiFi.

Is it relatively straightforward to simply not allow image replacement on smaller mobile screens?

skip svg

I got an email from someone who's using svg in img tags, saying that retina.js tried to swap those. I verified it and pushed up a small fix to my repo. I haven't added tests so I haven't sent a pull request yet.

404 pages returned as 200 status code causes blanked images

I've noticed this happens when using hosting such as http://staticloud.com/, because they do not return a proper 404 response when a file isn't found. They instead just return a page indicating that the page could not be found, but the response is 200.

Example '404' page:
http://ciclismo.staticloud.com/kjskldjld

$ curl -I http://ciclismo.staticloud.com/kjskldjld
HTTP/1.1 200 OK
Date: Wed, 22 Aug 2012 17:29:59 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: sessionid=92035ab79247950b011a4084217e550b; Domain=.staticloud.com; expires=Thu, 22-Aug-2013 17:29:59 GMT; Max-Age=31536000; Path=/
Server: gunicorn/0.12.0
Vary: Cookie
Set-Cookie: sessionid=a2cea44f070eebdf9498e4bee053c87e; Domain=.staticloud.com; expires=Thu, 22-Aug-2013 17:29:59 GMT; Max-Age=31536000; Path=/
Cache-Control: no-cache

Because it returns a 200, retinajs thinks the image is actually there, and tries to load it in, which causes the image to blank out rather than just using the original image.

While not a bug with retina.js, I have a few friends with sites on staticloud and have updated retina.js to check for a proper content-type before loading the @2x image.

Not sure if there is interest in pulling this in, but I'll attach a pull request to gauge interest and to see if there are better ways to work around this.

Deals oddly with some 404s on Chrome

Hi, this page of my blog does not have any retina images available:

http://emptysquare.net/blog/boxing-in-the-basement/

In Firefox on a retina display, retina.js attempts to load the @2x versions and doesn't find them, no problem. On Chrome, however, some of the nine regular images are replaced with broken image icons. On each reload, some random images are replaced w/ the broken icon, some aren't. Chrome Version 24.0.1312.56, Mac OS Mountain Lion.

Screen Shot 2013-01-22 at 10 06 10 PM

I don't see any difference in my server's responses to retina.js's queries:

$ curl -I http://emptysquare.net/blog/media/2012/12/[email protected]
HTTP/1.1 404 Not Found
Server: nginx/0.8.54
Date: Wed, 23 Jan 2013 03:11:02 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Content-Length: 69
$ curl -I http://emptysquare.net/blog/media/2012/12/[email protected]
HTTP/1.1 404 Not Found
Server: nginx/0.8.54
Date: Wed, 23 Jan 2013 03:11:28 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Content-Length: 69

... so I don't see why retina.js is incorrectly replacing some of the images with retina versions that don't actually exist.

Using Retina.js with sprite images

Is it possible to use Retina.js with a sprite image when you specify sprite image location in a css stylesheet? When I think about it it doesn't seem like it's possible.

Don't load default image, only load @2x

Hi, and thank you for your great job.

I've a problem.
I've insert the retina script in my web page.
When in my webpages there are the @2x image on the same folder of the standard image there aren't problem and the script work very well.
But if i don't have the image (@2x) on folder, the script don't show the normal image.

Sample:
FOLDER > image.png + [email protected] (WORKS)
FOLDER > image.png (Don't show the image standard )

There are a solution?

Thank's

Does it still need to load retina images on the iPhone?

Hi,

Great script but I have a question.

The script works great for iPad and Macbook Pro Retina but isn’t it unnecessary to serve @2x images for iPhone since it compresses the images down anyway?

Serving @2x images on iPhone that sometimes has a slower connection is wasteful.

Missing license

I was packaging retina.js for cdnjs [1] but didn't found any license under which the software is released. Could you please provide one? Also any chance you can tag a release version? This way it would be easier to update. Thanks in advance

[1] https://github.com/cdnjs/cdnjs

offsetWidth/offsetHeight vs width/height

I'm curious about the use of the offsetWidth/offsetHeight attributes versus width/height attributes. In my website it causes the images to appear in the wrong size because it includes the padding values from the original image.

The @2x image appears at width=originalWidth + padding instead of just the width.

Is there a reason for this choice?

Thanks,

Dougal

iPhone 5 Issues

The script is not functioning when using on the iPhone 5, cross comparison with the iPhone 4S and iPad 3 shows that it does work on those devices. Must be lacking support for the latest iPhone's display (size)?

What if I want to server @2x images by default?

It seems as though this will only work if the coded image is "image.png" and there is a @2x image on server.

What about if I want to serve @2x by default in some parts of my site?

Is there any way to make this work?

Some images not being replaced, work briefly on device rotation

I have a website that i'm currently building that has 2x images for everything.
Certain icons however, aren't being replaced for their 2x versions as expected. They all have 2x version named correctly and everything should be working fine.

Here's the weird thing though: If you rotate the device (i'm using an iPad 3) , the correct 2x image is briefly show, then removed again (putting back the 1x version) after the device rotation as been completed.

All the problematic images displaying this behaviour are in HTML - they're not background images being applied by CSS.

Any ideas on what might be causing this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.