In CSS, can you encode an image in base64?

I just ran into this while looking at CSS code:

background-image:url(data:image/png;base64,LKJSDLKJFSLDJFKDJFLJS......) 

It seems that the actual image was encoded, it is a widget that is located on the website, so it seems that it is being executed for efficiency reasons, so it does not need to make a request to the web server.

Is this cross browser safe? This is news to me!

+4
source share
4 answers

It is supported in all major browsers, yes. However, IE7 and less do not support it, and IE8 needs less than 32K (which should not be a problem). IE9 does not have this limitation.

http://en.wikipedia.org/wiki/Data_URI_scheme

+2
source

Yes, but your URL should be below 32k for IE8.

+1
source

There are hacker ways to do this for IE6 / 7 using MHTML

See http://www.phpied.com/mhtml-when-you-need-data-uris-in-ie7-and-under/

Turbine (for PHP) will convert images less than 25 kb in data URI or MHTML automatically

See http://turbine.peterkroener.de/docs.php#plugins-datauri

0
source

Source: https://habr.com/ru/post/1338793/


All Articles