To be honest, I would not use Phoenix just to serve static files. As a full featured framework, Phoenix has a lot of stuff for different things and using it for just static files is a waste of resources and adds needless complexity.
Actually I have planned this same.
But as having a totally different dedicated server for front end will give me better load balancing and traffic management ( my opinion), I am trying to make a different phoenix assets provider.
Having two or more Erlang VMs on the same machine will result in more OS level context switching and thus worse performance. You would be better served with just one Phoenix instance in this case. Unless you are talking about a totally different machine, but then my point in the first post stands, it would be a waste to put Phoenix there just to serve static assets.
So what you can do, and - in fact - I do it, is that you start two, not one Phoenix instances.
I assume you have a single page app here.
You can have an umbrella project, what I would do (and in fact I did in the past is to have):
web - Phoenix front-end, started on port say 4000. There is just one catch-all controller, mounted with: get("/*path", PageController, :index) in router. The controller only outputs the index.html file fount in web/priv/static for all requests. In development mode it is also configured to live reload stuff. So everything you drop into web/priv/static gets served already using Phoenix’s plug for serving static files. We needed the catch-all route since it’s a client-side routing and when user reloads the page on given URL we still want to serve initial index.html and then JS routing takes over when the JS apps loads.
api - Phoenix API, started on port say 4002, multiple controllers, channels etc. all go here.
and then obviously some other apps I might have like core or db or whatever else I decide to split the app into.
Totally agree @hubertlepicki
Thanks for the elaborated explanation, I also liked the setup to make things cleaner for initial phase.
Sir, if possible please explain a bit more on how can I serve the files based on url enter (lazy loading), i.e only that much of bundle will be served. Say the generic bundle and a page specific bundle, not whole. Just to make an speed enhancement.
Here, I have basic idea of setting routes function based on urls and serving files on that only, but not too sure.
I would love to know that myself in fact. I never had to do that and so far it was okay to bundle everything up together. But I can definitely see the value in doing that, just that I have zero experience in the area.