Question about assets in umbrella apps - how to maintain consistency of assets?

My case is, in my project we need to use different web apps inside the same umbrella application each one with different endpoint. My point is how do I maintain consistency for the same css file and if its possible to mantain the js too? Can you share your xp for this situation?

E.g.
Umbrella

  • Backoffice
  • phx_web_1
  • phx_web_2
1 Like

:wave:

I’d consider moving the assets to a separate app, and make the other web apps depend on it.

1 Like

What are the downsides of having app just for assets? Are there other mechanisms to share assets in umbrella apps that don’t depend on having an app especially for serving assets?

Also, what would your proposal look like? I’m having a hard time seeing how depending on an app with assets would work…

having an app especially for serving assets?

Not serving, just having them in its priv. The web apps that depend on it would probably serve the assets themselves. There just needs to be a “single source of truth” for the web apps to depend on.

Also, what would your proposal look like? I’m having a hard time seeing how depending on an app with assets would work…

It might be as simple as a :assets app with some static assets in its priv/ folder. The static plugs in the web apps would then just use something like plug Plug.Static, from: {:assets, "priv/static"} to serve them.

What are the downsides of having app just for assets?

Having an app just for assets. Which is more complexity, more explanations to other team members why and how it’s done that way.

Are there other mechanisms to share assets in umbrella apps

Yes, a cdn, a frontend setup separate from phoenix, a symlinked folder (that might actually be a good idea)?

1 Like

I haven’t tried this personally, but I suspect you could put an assets/ folder in the root of the umbrella and each contained app could reference it via relative path.

2 Likes

And it could be copied into a release as well, but making it work with a static plug would be a bit error-prone.

@gregvaughn @idi527 It’s interesting you say that. It makes me wonder: Is it unusual to have an umbrella app with two x_web apps inside? Or is it the sharing assets part that people don’t usually do?–leaving assets separate? I’m thinking of having several x_web apps within a phoenix umbrella. Initially, they will all depend on a single db with a back office app. So doing it in a single umbrella keeps things simple.

@idi527 a CDN would work, but that means some manual work to sync the files and so on. We would still need a place to edit and bundle them before pushing them out to the CDN.

My team had similar ideas last year. We were going to have multiple Endpoints, each in its own app and use a plug to route between them based on the first element of the path of the request. One of my teammates explored refactoring our project to that architecture, and I recall sharing of assets coming up as a question. Ultimately he decided it was too complex a refactoring for us to do at that time.

I don’t say this to discourage you. This may be a much better fit for your project and it probably is simpler to start with rather than refactor to. What we opted for instead were separate business logic apps (like an overgrown context) and a shared “web” app.