Wondering if there’s a way to get the Render web server serving static assets built by Rails - in the docs you suggest enabling Rails’ built in file server, but ideally that would happen beforehand.
Probably possible to do something with Docker, but I wondered if there were magic paths or extensions that render understood
The only downside really is taking up a relatively expensive app server process (in terms of memory footprint etc) to serve an asset when it could be done more efficiently (and potentially faster?) by a dedicated webserver. I don’t think it’s a massive impact unless your application is very read heavy and/or has a lot of static assets.
You could create a static site (Free Static Site Hosting | Render) to host your static assets by having the build command just ask rails to generate the assets. Your actual rails service could then serve those assets, as long as you configure your service to point to your static site.
This sparked my interest as I’ve been experimenting with Render deployments myself. Here’s what I did…
I created a static site in Render and set the build command to precompile the assets and ./public as the publish directory. I had to add a bunch of environment variables so that the precompile would run successfully.
Cool - so one thing I’m concerned about is race conditions in the deploys. Specifically - I’ve had issues in the past where:
App finishes deploy
User access App, pointing them to get a new asset (like a .js file)
Asset host doesn’t have the new file yet - so it returns a 404
CDN caches the 404
Asset host finishes deploy - and gets the new asset
CDN continues to return 404 because of the cache
Is this race condition possible in this setup? How do cache-control headers get set on the static assets? Can the 404 cache time be set differently than the static assets?
User loads App (Version 1). It’s a single-page app with a large Javascript bundle that uses code splitting.
App deploys Version 2
User switches pages on single-page app, triggering the loading of a file in the Version 1 bundle (due to code splitting)
Does that V1 file still exist on the CDN?
For a typical CDN - I’d expect a cached file to exist in memory for a period of time after a deploy. (The other solution is to sync new files to an S3 bucket, and never delete the old files).
Yes, we continue to serve assets from V1 to avoid that version mismatch. Should all work for you V2 assets with the same URL will be replaced, but if the URL of a V1 asset is not overwritten by a V2 asset, you will continue to see the V1 asset.
Good idea! We do have a feature request open for something similar (Cloud Object Storage | Feature Requests | Render), but I’m not sure where it might be on our product roadmap. I encourage you to upvote it and add your usecase, since that’ll help us prioritize and design it
Ahh, I’ve been battling out of memory issues I think I’ve largely tracked down to having puma serving assets. So this looks like a great solution.
I’m having an issue where my asset fingerprints differ on the static app vs the running rails instance, and I’m having a hard time figuring out what’s going on. Did anyone else run into that? Things I’ve checked: