intertwingly

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