Hacker News new | ask | show | jobs
by dwnoiz 5178 days ago
While this script is fine, it adds an extra HTTP request per image to check for a retina version of the image. Also, the browser will start downloading the small version before it loads the big version (adding another extra http request). Check this easy jQuery snippet that does the same thing, but avoids these issues:

http://www.archer-group.com/2012/development/javascript-jque...

1 comments

There are several problems with this implementation.

1. The image doesn't have a src attribute. This means if that script fails for any reason then none of the images on your site load.

2. You need to have width and height attributes on all of your images. This is a nightmare for both dynamically generated content and for responsive designs.

3. You need to have those two extra attributes on each of your image elements in order for it to work.

Our goal was to make retina.js zero-config. We wanted it to work on existing sites without any changes to the existing markup.