It’s just data

Binary Free

On a lark, I converted the few images referenced by my CSS file to data URLs.  Seems to work just fine in the latest release of all major browsers.

I used the following simple script to do the conversions:

require 'net/http'
ARGV.each do |arg|
  url = URI.parse(arg)
  Net::HTTP.start(url.host, url.port) do |http|
    res = http.get(url.path)
    break unless res.code == '200'
    data = 'data:'
    data << res['Content-Type']
    data << ';base64,'
    data << [res.body].pack('m').chomp.gsub("\n",'')
    puts data
  end
end

Data URLs work fine in everything except IE 6 & 7. If you really want to hit those two as well, there’s a trick involving MHTML.

Posted by Yoz at

Sam Ruby: Binary Free

[link]...

Excerpt from Delicious/tag/ruby at

On the Interwebs Recently, number 12

Some websites I have found interesting (in no particular order): Why do we have an IMG element? : Very interesting look back at the early days of the internet. Makes it a lot easier to see how we got to HTML5. Man, that Mark Pilgrim has been on a...

Excerpt from Benjamin Thomas at

Answer by Pete Kirkham for include image in XML file

You could encode the image as a data URI , which most browsers seem to support now . It’s still base 64, and so less compact than a separate binary file, but it is a standard way of inlining small images....

Excerpt from include image in XML file - Stack Overflow at

Add your comment