CDN for Ruby on Rails
Let Rails run the app. Let Cloud CDN run the assets.
Rails clusters should not spend Puma or Sidekiq-adjacent capacity serving digested assets and public blobs to every region.
Set asset_host to Cloud CDN. Cache public Active Storage URLs. Cache anonymous pages where possible. Bypass session views and POST.
Why teams use Aptranet
What CDN for Ruby on Rails looks like on this network.
Cloud CDN caches and accelerates eligible content on 210+ points of presence, with Origin Shield when the origin must stay out of the way.
Digested assets at the edge
Propshaft or sprockets files are cached on 210+ PoPs.
Public blobs worldwide
Active Storage public variants can be cached and transformed at the edge.
Session views stay in Rails
Devise, dashboards and CSRF forms are not cached.
How to set it up
A cutover you can validate before DNS moves.
Create the Cloud CDN configuration, prove it on an Aptranet hostname, then point production DNS when the path looks correct.
- 1Set config.asset_host
Point digested assets at the Cloud CDN hostname.
- 2Cache public storage
Put public Active Storage URLs on the same distribution or a media hostname.
- 3Optionally cache public HTML
Marketing pages can be cached with purge on deploy.
- 4Bypass authenticated Rails
Keep session cookies out of the cache key for app HTML.
Outcomes
What changes once the hostname is on Aptranet.
- Rails assets are delivered globally
- Public storage is cached at the edge
- Session HTML remains dynamic
- Puma spends less time on static files
Keep reading
Related pages
More CDN use cases on the same Cloud CDN footprint.
Frequently Asked Questions
Yes. Both emit digest filenames that Cloud CDN can long-cache.
Fragment cache remains in Rails. Cloud CDN caches full anonymous responses you mark as public.
Keep private blobs on signed origin URLs. Cache public blobs only.
Cache full documents that are shareable. Turbo Drive requests that vary on session should bypass cache.
