0

In the Create React App documentation inside the Adding Images, Fonts, and Files section, they say :

importing images that are less than 10,000 bytes returns a data URI instead of a path. This applies to the following file extensions: bmp, gif, jpg, jpeg, and png.

The reason for them is :

To reduce the number of requests to the server

But is it specific to how React works (updating the DOM for example) or it's a wide spread practice in web development in order to reduce load times?

johhnry
  • 29
  • 1
  • 4

1 Answers1

1

This is not a practice that's particular to React. Whether something gets rendered via React or by ordinary HTML, if an image is rendered using a data URI, if the data URI exists in the code already (either bundled inside the JS or hard-coded into the HTML), no additional requests to the server will have to be made.

In contrast, if you have something like src="theImage.png", that'll result in a request to the server to download the image.

it's a wide spread practice in web development in order to reduce load times?

Yes.

If, for example, the web server was using HTTP 1.1, and you had, say, 25 images with srcs pointing to different files, the sheer number of separate requests could present a problem - regardless of whether React was being used or not.

(HTTP/2 mitigates this problem at least somewhat - see here)

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320