M
M
Maxim Tarabrin2017-07-12 12:27:57
JavaScript
Maxim Tarabrin, 2017-07-12 12:27:57

Why are images encrypted?

I often see how the encrypted image code is located in img. What is it for? How is it done? Manually encrypt and paste this code into img or what?
For example:

<img *ngIf="loading" src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==" />

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2017-07-12
@padr1no

It's not encryption, it's base64 encoding.
Is being done. because the HTTP protocol is not designed to transfer binary data, only text. And the pictures contain non-printable characters that cannot be transmitted over the HTTP protocol.
Therefore, if an image is embedded directly into the html content, it is encoded in base64. The size increases by about a third, but it can be transmitted via http as text

R
RubaXa, 2017-07-12
@RubaXa

Hmm, https://ru.wikipedia.org/wiki/Data:_URL

A
Andrey Pavlenko, 2017-07-12
@Akdmeh

It is done to reduce the number of requests to the server. After all, each image is an extra request to nGinx, and sometimes, if there are about 50 icons, the load increases significantly. In this case, increasing the image size by 30% is a lesser evil than another extra request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question