Last active
August 29, 2015 14:18
-
-
Save caiotarifa/f748d357293285186411 to your computer and use it in GitHub Desktop.
External and Cacheable use of SVG (with Rails)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def svg_use file, options = {} | |
| content_tag :svg, options do | |
| content_tag :use, nil, :'xlink:href' => asset_path(file) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .icon { | |
| display: inline-block; | |
| fill: currentColor; | |
| height: 1em; | |
| width: 1em; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= svg_use 'icons.svg#undo', class: 'icon' %> | |
| <svg class="icon"><use xlink:href="icons.svg#undo"></use></svg> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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