5

I am trying to use SVG icons as described here https://css-tricks.com/svg-use-with-external-reference-take-2/

(here is how it looks)

<!-- EXTERNAL reference -->
<svg>
  <use xlink:href="sprite.svg#icon-1"></use>
</svg>

it works for me without any problem except if I open html file locally in Chrome.

in dev tools it shows this error:

Unsafe attempt to load URL file:///D:/path/to/file/icon-defs.svg#icon-rocket from frame with URL file:///D:/path/to/file/index.html. 'file:' URLs are treated as unique security origins.

is there any way around it? most of the time i use firefox so it is not a big problem for me but i am building documentation in html format that would be used by other users...

Marek
  • 267
  • 1
  • 3
  • 9

2 Answers2

2

There is no real way to bypass the file: safety thing.

But you could always embed the SVG directly into your HTML file and just <use xlink:href="#icon-1" /> - keep in mind that it will increase the size of your HTML, but since it's for documentation rather than being downloaded repeatedly over the web, this may be acceptable.

In any case, be sure to optimise your SVG files. I've found this SVG optimiser to be outstandingly effective.

Niet the Dark Absol
  • 301,028
  • 70
  • 427
  • 540
0

Start Chrome with the command line option --disable-web-security

be careful not to surf the web generally with Chrome when run with this flag.

Robert Longson
  • 102,136
  • 21
  • 218
  • 211