tags:

views:

472

answers:

3

Example:

<div id="sampleimage">

***Stream or Serialize JPEG Image from Server Here w/o Sending another Request***

</div>

So basically, send everything in a single response.

+4  A: 

In some browsers (in FF, Chrome, and apparently IE8) you can use the data URL scheme to embed an image file in HTML.

It looks something like this (taken from the RFC):

<IMG
   SRC="data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw
   AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz
   ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp
   a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl
   ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis
   F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH
   hhx4dbgYKAAA7"
   ALT="Larry">

You can see that the data for the image is encoded in base64. I believe you can also use this format to assign images in javascript and to use them in CSS.

Daniel LeCheminant
I believe this works in IE8
apphacker
@apphacker: Thanks, I've modified the answer to reflect this
Daniel LeCheminant
So IE7 doesn't allow this?
danmine
@danmine: I don't think so.
Daniel LeCheminant
But this doesn't work in IE so... you can't.
cletus
Just because IE is broken, that doesn't necessarily mean there isn't an application for this (useful) technique.
Alex Reynolds
A: 

See: Scripting Remote Images in JavaScript. Alternatively, embed your image data in the HTML in Base64 encoding.

Alex Reynolds
This scripting example doesn't embed the image in a single stream, it just preloads it. And base64 encoding isn't supported by IE (pre-8).
cletus
IE isn't the only web browser out there.
Alex Reynolds
Oh my God, I can't believe you even said that. So putting in something not supported by 70% of your users is OK? Seriously?
cletus
Sure, just do a user agent check and redirect appropriately. SVG doesn't work in IE. PNG doesn't work in IE. But the world doesn't revolve around Microsoft and people still find uses for SVG and PNG formats.
Alex Reynolds
+3  A: 

Yes, it is possible: See here

Johannes Weiß
This doesn't work in IE6/7 either...
cletus
He asked about HTML not about a specific (broken) implementation.
Johannes Weiß