Skip to content

Instantly share code, notes, and snippets.

@johnantoni
Last active August 29, 2015 14:21
Show Gist options
  • Save johnantoni/32eb408a46f06d7ad530 to your computer and use it in GitHub Desktop.
Save johnantoni/32eb408a46f06d7ad530 to your computer and use it in GitHub Desktop.
svg images
  1. load svginjector https://github.com/iconic/SVGInjector
  2. place your svg + png fallback files in [see 'file layout']
  3. make sure loadSVG() is run on page load / page ready.

Now when your browser can't use the svg file, it'll fallback to the png equivalent inside the 'fallback' directory.

Also here's the svg optimization tool which was mentioned, https://github.com/svg/svgo-gui

Enjoy.

[ file layout ]
/svg
  logo.svg
/svg/fallback
  logo.png
<img class="svg" src="/svg/logo-text.svg" alt="UXGent"/>
loadSVG = function() {
var mySVGsToInject = document.querySelectorAll('.svg');
var injectorOptions = {
evalScripts: 'once',
pngFallback: 'svg/fallback'
};
SVGInjector(mySVGsToInject, injectorOptions);
};
loadSVG();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment