Skip to content

Instantly share code, notes, and snippets.

@caiotarifa
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save caiotarifa/f748d357293285186411 to your computer and use it in GitHub Desktop.

Select an option

Save caiotarifa/f748d357293285186411 to your computer and use it in GitHub Desktop.
External and Cacheable use of SVG (with Rails)
def svg_use file, options = {}
content_tag :svg, options do
content_tag :use, nil, :'xlink:href' => asset_path(file)
end
end
.icon {
display: inline-block;
fill: currentColor;
height: 1em;
width: 1em;
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<%= svg_use 'icons.svg#undo', class: 'icon' %>
<svg class="icon"><use xlink:href="icons.svg#undo"></use></svg>
@caiotarifa
Copy link
Copy Markdown
Author

There is a good library that provides a fallback for IE 9-11, requesting the file by ajax. In IE6-8 the library changes the tag to allow use PNG.

https://github.com/jonathantneal/svg4everybody

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment