class Sprockets::Context

def asset_data_uri(path)


$('').attr('src', '<%= asset_data_uri 'avatar.jpg' %>')

#logo { background: url(<%= asset_data_uri 'logo.png' %>) }

Use `asset_data_uri` from ERB with CSS or JavaScript assets:

of the current file.
asset at the specified path, and marks that path as a dependency
Returns a Base64-encoded `data:` URI with the contents of the
def asset_data_uri(path)
  depend_on_asset(path)
  asset  = environment.find_asset(path)
  base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
  "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
end