Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can reference elements from an external file just as well:

  <use xlink:href='icons.svg#foo'/>
Theoretically the browser should only download that file once, just as with multiple img elements referencing the same image. I haven't seen that approach much in the wild, though.


This approach prevents CSS styling though since SVG referenced this way has its independent DOM and is not part of the current page DOM.


Yes, in that sense it's more like CSS sprites, just a bit easier to use.


Good to know. This has me thinking it'd be cool to have a babel plugin or something that extracts out svgs like this. I currently have a website that heavily uses svgs and for the bulk of them I resorted to img elements because embedding the svg so many times increased the size of the html significantly. This use approach seems like it might be better.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: