steveo225
steveo225

Reputation: 11872

Use a base64 embedded image multiple times

I have a couple small images in an HTML document that I want to make portable, e.g. still works when emailing. I use the following, which works great:

<img src="data:image/png;base64,..."/>

Problem is, I want to use the same image many times in the document, but don't want to repeat the entire base64 data string. I have seen in emails where the data is encoded a single time, but referenced many. Is this possible with HTML?

Upvotes: 12

Views: 4376

Answers (2)

Gerben
Gerben

Reputation: 16825

Configure your webserver to zgip (/deflate) your content. Deflate should detect the repeating string and compress to about the same size as you would have if you only included it once. This way you won't waste bandwidth. Doesn't work for email, or for plain html-file in filesystem.

Upvotes: -1

alex
alex

Reputation: 490123

If you can use CSS, you could place it there instead, as a class.

Then just add the class to the elements you want.

Upvotes: 9

Related Questions