Programmatically bust CDN Cache
sreeambat
PROOP

a month ago

Is there a way to programmatically bust the Railway CDN cache? If not, is it on the roadmap?

image.png

Attachments

8 Replies

a month ago

Not something we provide right now, and it is not on a roadmap.


therobotcarlson
PRO

a month ago

If your goal is cache busting frontend files being served, most CDNs cache by the full string, query included. A common method I've seen is having each release attach a custom query string to the end of files. Like: app.js?v=build_hash most JS bundlers do this by default these days


therobotcarlson
PRO

a month ago

So the question is: how does railway CDN cache? full query string? I would guess yes since I haven't see issues in my builds.

You can usually also use cache-control headers.

If you need to "bust" the cache just for you and your browser, you can also randomly append query strings on the end like ?q=1 or something. Ones that are meaningless to your app, but the cache will see as a different "key" to return content under, so it does a real lookup


sreeambat
PROOP

a month ago

Thanks. I want to invalidate the current cached item(s) after a new bundle is built. I have a manifest file that contains the file name. But the issue when I turn on CDN Caching, I think, both bundle and the manifest file are cached. Hence I will need the manifest cache to be invalidated for the clients to pick up the new bundle


therobotcarlson
PRO

a month ago

yes, so that's where you can add the build_hash query string to the end of the url when fetching the manifest for clients. It ensures everything is cached until you update


therobotcarlson
PRO

a month ago

That's the "programmatic" solution


a month ago

If you'd like to purge a single asset, you can use the HTTP PURGE method.

e.g. curl -X PURGE


sreeambat
PROOP

25 days ago

Thank you both!


Welcome!

Sign in to your Railway account to join the conversation.

Loading...