Last Updated: February 25, 2016
·
1.572K
· herschel666

PNG-Fallback for SVG-Images

Inspired by this snippet: http://codepad.co/s/02aac9, I wrote an alternate version that doesn't depend on jQuery for replacing all SVG-suffixes with the PNG-suffix on inline-images in the markup of a site.

One just has to provide the referenced fallback-images.

var rSvg = /\.(svg)$/;

if ( !Modernizr.svg ) {
  for ( var i = 0, img; img = document.images[i]; i += 1 ) {
    if ( !rSvg.test(img.src) ) continue;
    img.src = img.src.replace(rSvg, '.png');
  }
}

The only dependency is Modernizr.

(https://gist.github.com/herschel666/5024092)