Joined July 2015
·

Sam Dean

London
·
·

Hey.

I've taken your method and done this to it :

def retina_image_tag(default_name, options={})

    retina_name = default_name.gsub(%r{\.\w+$}, '@2x\0')

    image_tag('', options.merge('data-interchange' => "[#{path_to_image(default_name)}, (default)], [#{path_to_image(retina_name)}, (retina)]")) \
    + \
    "<noscript>#{image_tag(default_name, options)}</noscript>".html_safe
end

This does:

1) Use path_to_image instead of asset_path so it works with images that aren't in the asset pipeline

2) Don't load the default image regardless of display state - always use interchange to load the image via javascript and only if javascript is disabled use the default image as the image src. Should save on bandwidth on retina devices.

Hope this is helpful :)

Achievements
1 Karma
0 Total ProTip Views