> ## Content Index
> Fetch the complete content index at: https://larrysalibra.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Assets & IPv6 on Ruby on Rails
- URL: https://larrysalibra.com/assets-ipv6-on-ruby-on-rails/
- Published: 2010-02-18T16:00:00.000Z
- Updated: 2010-02-18T16:00:00.000Z
- Author: Larry Salibra
- Tags: technology, blog, #Import 2024-08-23 13:31

All of our internal production sites starting in 2009 have been launched with dual stack IPv4/IPv6 from day one. We typically serve static assets (images and javascript) from our content delivery network to improve load performance. Unfortunately, the CDN we use is IPv4 only. The following Ruby on Rails code snippet is from `/config/environments/production.rb` that rewrites static asset paths to serve from the RoR server for IPv6 and SSL requests and the CDN for IPv4 requests.

{% codeblock %}  
ActionController::Base.asset\_host = Proc.new { |source, request|  
remote\_ip = IPAddr.new(request.remote\_ip)  
if request.ssl? || remote\_ip.ipv6?  
"#{request.protocol}#{request.host\_with\_port}"  
else

# replace your.cdn/path with the host + path to your IPv4-only CDN

"#{request.protocol}your.cdn/path"  
end  
}  
{% endcodeblock %}