Storing avatars in base64 in files

Hello everyone

How about converting photos to base64 when uploading files, and saving the code to the same file, and then loading avatars in the template using file_get_contents ()?

<img src="data:image/png;base64,<?=file_get_content($user->avatar);?>">

The weight of avatars is not more than 50-70 kb, the dimensions are 200x200. There will also be 50-100 avatars per page.

Does this make sense?

 0
Author: Виталина, 2014-09-05

1 answers

Modern operating systems (in the sense of Linux :) use free RAM for caching disk operations, so that if there is excess RAM from the disk, avatars will be read only once. In general, this, in my opinion, you can not really bother.

In this case, another cache is more interesting, the cache on the client. GET requests are cached by the client (if the server returns the appropriate headers). With the correct server caching headers, the client, when visiting the page again, it won't even request avatars, just show them from the cache.

Data url inserts are always downloaded, because it's just part of the page. But 100 avatars of 70 Kb is 7 MB. In addition, there are fans of blocking adblock-om gif-avatars (that would not distract), or even prohibit the loading of images, to save traffic. In your version, they will break off.

If we are talking about a forum, then all the more or less active forumchane quickly zakeshiruyut avatars of each other.

 0
Author: MrClon, 2014-09-05 12:15:53