Inline Data

By on June 30, 2004

Here’s a crazy little tidbit that you should probably never use on a normal web page: Thanks to RFC 2397, some browsers include the ‘data:’ url type, which lets you embed data resources right in your page. For instance, the image attached to this post looks like this:

Mozilla folks can see a nice little ‘Dave’ logo. Unfortunately, IE doesn’t implement the spec, so it’s a happy red X for you folks, sorry.

What Links Here


  1. That’s a lot like embedding pictures in emails, I imagine. Or like Microsoft’s HTML Archive (.mht) format.

    Seems handy on the surface, but one can only imagine the security implications.

  2. On the surface, it seems handy for small images (‘Hey, I can have any kind of bullet now!’), but then you have to include the whole thing for every instance on the page, which defeats the purpose of the browser cache. I wonder if it would work as a CSS image reference. That would make (slightly) more sense.

    If you want to try it out, here’s the Ruby script I used to encode the image:

    require “base64”

    img =“C:\testlogo.gif”, “rb”) {|file| buff=” file.each_byte {|byte| buff < < byte} buff }

    puts encode64(img)

    Obviously, replace “C:\testlogo.gif” with whatever it is you want to encode.

  3. Opera also supports the scheme, at least as of version 7.54.

    Hm, seems IE is lagging even more behind than it used to (I am thinking of missing CSS 2.1 support as well)…

  4. In order to prevent some browsers from submitting forms when the user presses enter on an input field, I like to use this url type, and put this invisible button on the page before the first real submit button:

    However, when the page containing that is loaded over https, Internet Explorer, at least versions 5 and 6, complain about the page containing both encrypted and non-encrypted items, rendering this technique useless in many cases.

Comments are closed. If you have something you really want to say, tweet @gadgetopia.