1

I want to include some SVG images in my HTML file. I am using ReactJS and including them by using <img> tag.

<img src="path_to_svg"></img>

Now each of these images, as expected, are causing XHR network requests. I want to prevent XHR requests for performance and security concerns.

What is the best way to achieve this? Should I consider corverting SVG code to Base64, and include the CSS as background?

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35
Atishay Baid
  • 339
  • 2
  • 7

1 Answers1

1

I think your two options are to either use data URIs for your images or use sprite sheets.

The problem with data URIs is that your images won't be cached unless the document they're in is cached (HTML file or CSS file). But there are some things you can do to help with that.

The sprite sheet solution won't prevent all your network calls but it will limit it to only one, if that's a viable option.

Community
  • 1
  • 1
jaybee
  • 2,240
  • 14
  • 20