iconic / SVGInjector

Fast, caching, dynamic inline SVG DOM injection library
MIT License
974 stars 145 forks source link

Add CORS initiation to XHR request object #20

Closed PrototypeAlex closed 1 year ago

PrototypeAlex commented 9 years ago

Adds CORS to the request for the SVG file, only if the server supports it will this effect the request.

If you're loading this script from outside of your domain, or your svg files live on a different server/domain than where the javascript file originates from then you'll probably run into cross origin request issues. This patch solves that by adding CORS to the xhr request, i.e. adding the ORIGIN header to the GET request.

If CORS isn't supported then an error will occur, but this is OK, because if the browser doesn't support CORS, then it doesn't support SVG, looking at IE specifically, there could be edge cases to this? If there is, and you're reading this, please ping me and I'll write a condition for the browser in question.

protodave commented 9 years ago

Awesome, thanks Alex! I'll give this a spin and also double check it when it's integrated into iconic.js, etc, then I'll get this added.

protodave commented 9 years ago

I finally got around to playing with this and created a cross-origin test case page and IE9 VM setup. Quick update from what I learned so far...

So, looks like it will take a bit more wrangling and testing to refactor properly. I'll keep at it. Thanks again Alex!

adg29 commented 9 years ago

Hey @protodave, any luck getting this PR in shape for further testing? Thanks for the initial effort in any case!

protodave commented 9 years ago

Hey Alan! Thanks for the nudge... I'll work on setting aside a day soon to get this, and a couple other overdue PRs and updates, over the finish line.

Also, if you have a specific use case let me know so I can test against it. (ex: CDN hosted SVGs for IE9 maybe?)

longzheng commented 9 years ago

Any updates on this?