CDN for static assets in backend apps
planned
K
Kai Marshland
I would like to use Render's CDN for static sites to serve static assets for my non-static apps built with frameworks like Rails or Django.
This would let me turn off the option for Rails to serve static files. In a typical setup, this would be off and static assets would be served directly from the CDN and these requests would never hit the (comparatively slow) Rails app.
Log In
g
guesses_01vinyl
When did this move to 'Planned'? I am trying to get a feel of if this has been in the backlog for a long time, or whether to plan around it in the short to medium term.
p
pbruvoll
I would also like to add a +1 for this feature. Similar to Dexter I have deployed a Remix app (Node, express and serverside renderend React) with Cloudlfare in front. Beeing able to use the cache would be crucial to make the page faster for the user and take a lot of load off the Remix app and the backend it retrieves data from. I would really like for the cache to respect the Cache-Control headers set on all my files, includeing html, css, json, javascript and images.
Apperantly, it is not possiblet to get Cloudlfare CDN to respect Cahce-Control headers since Render's settings is overriding it.
I've talked to cloudlfare about it here: https://community.cloudflare.com/t/not-able-to-cache-static-assets-in-cloudflare-cdn/555484/4
"Render woud have to follow through with their plan to permit CDN Cache Control headers at their end."
I have also tried to use Cloudflare's Cache Rules, but have not had any luck with that.
Sadly, this currently seems like a showstopper for going forward with this app hosted on render with Cloudflare CDN in front.
But I have implemented a memorycache in node, so I'll give that a shot and see how it works out regarding speed and workload againt the backend.
h
hello
This can be achieved using Cloudflare's Cache Rules (Still in beta though) https://developers.cloudflare.com/cache/how-to/cache-rules/
You can set a rule to override Edge TTL which will cache it on your Cloudflare regardless of what settings Render is using.
p
pierrick.martinez.fm
+1 for this features
R
Richard Wilson
Oh wow, I just found our Render silently exports the $RAILS_SERVE_STATIC_FILES env var that configures production to serve these by default (unless you change it from the default rails new) so I just noticed it wasn't nginx or something doing this behind the scenes. How? A basic proxy pass nginx configuration isn't a lot to do for assets.
A
Agis
Is this getting done anytime soon? It's been in the Planned stage for 3 years now and it's one of the most requested items. Anurag Goel what's the status here?
Anurag Goel
Agis: still on our roadmap. For now, does putting a free CDN (e.g. Cloudflare) in front work for you?
A
Agis
Anurag Goel: I already have Cloudflare in front. The issue is that, for CSS/JS assets, Cloudflare reponds with
CF-Cache-Status: DYNAMIC
which I believe is due to the fact that Render also uses Cloudflare, and your settings override our settings.A
Agis
Anurag Goel any official responses here? Is my hypothesis above correct?
z
zach
Anurag Goel: I really need this feature for a app I’m building. It hosts maybe client’s domains, so I can’t setup cloudflare for all of them, I need it done at the service level
D
Dexter Miguel
This is a big +1 for me too. Remix allows us to specify Cache Control headers per route. Being able to have the cache the web app's specific routes on a CDN would be
fantastic
.Anurag Goel
Dexter Miguel: This is very much still on the roadmap, and as part of this work we will respect custom Cache Control headers for CDN caching. We're also planning to cache most static file extensions by default.
S
Sven Schwyn
Ouch, I only see this now after some load tests and might very much be a dealbreaker for us. Serving the assets through the app is not an option at all. And serving them seaprately from a static site (which does CDN) is ugly and error prone (deploy sync). Maybe you could consider a really easy to implement workaround for the time being? Add an asset directory to the backend config and serve it's contents by the Nginx proxy directly without hitting Passenger (for Rails). Here's the config we use on metal so far:
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
access_log off;
gzip_static on;
break;
}
Anurag Goel
Sven Schwyn: we plan to add far futures headers for all static file extensions listed here: https://developers.cloudflare.com/cache/about/default-cache-behavior/#default-cached-file-extensions. Will that work for you?
S
Sven Schwyn
Anurag Goel: Thanks for the update! The mentioned extensions would cover most of our use case. There are a few more (TXT for robots.txt, HTML e.g. for error pages like 404.html and JSON), but I see why they are not listed since they might break things for some sites. Do you thing this feature might be rolled before mid May? For an event, we expect a lot of traffic then which is why we migrate to Render in the first place.
Anurag Goel
Sven Schwyn: with a lot of constantly changing priorities, it's hard to pin down an ETA. We still expect to work on this feature this summer and will mark it in progress once we're actively developing it.
G
Guillaume Simard
This is one of the biggest drawback of Render.com vs Vercel when it comes to Next.js applications right now.
B
Ben Beecher
Big +1 for this feature. Might be worth thinking about how this integrates with CF since that's already in every deploy
Load More
→