Skip to content

Instantly share code, notes, and snippets.

@korotovsky
Created December 18, 2013 10:20
Show Gist options
  • Save korotovsky/8020127 to your computer and use it in GitHub Desktop.
Save korotovsky/8020127 to your computer and use it in GitHub Desktop.
Nginx locations for rewrite ordinary images to retina verstion with falback to ordinary if retina version is not present
###
# Retina images handler
###
if ($http_cookie ~* "isRetina=1" ) {
set $isRetina "retina";
}
location ~ ^/bundles/(.*)-retina\.png {
try_files /bundles/$1-retina.png @retinaFallback;
}
location ~ ^/bundles/(.*)\.png$ {
if ($isRetina = "retina") {
rewrite ^/bundles/(.*).png$ /bundles/$1-retina.png last;
}
}
location @retinaFallback {
rewrite ^/bundles/(.*)-retina.png$ /bundles/$1.png break;
}
##
# End retina handler
##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment