My company is working with a micro-frontend architecture for our application. It's a project I've been pioneering here and it has been quite successful so far. However, I'm hoping to get some advice on one of our outstanding challenges.
When you build a JavaScript application using Webpack, one of the options is to add a hash to the URL. This hash is generated with each build, so the hash would only change if there are changes to the file itself. So the filename would look like this:
app.ab12cd.js
The advantage to doing this is browser caching. Browsers will try to cache things to avoid having to consume too much data. So if it sees that same filename/URL again, it will just used the cached version rather than re-downloading it. Because the hash in the filename will only change if the file is re-built with changes, we can safely rely on the browser caching this file to reduce the over-the-wire download burden on our users while still being confident that they will always see the latest changes.
This is a challenge with our micro-frontend architecture. One of the guiding principles is for each micro-frontend to be individually releasable, meaning there is no direct dependency between the base application (ie, the initial one that the user navigates to) and the micro-frontend app that it will load.
We accomplish this through simple, static tags. Each time we add a new micro-frontend, we only need to update the base application once to add a new tag:
<script src="micro-frontend/assets/js/app.js"></script>
In the example above, that URL is redirected using an Nginx proxy to the actual, deployed micro-frontend. It's a relative URL for stupid and frustrating reasons involving our corporate infrastructure, but that's a whole other tangent.
The main point is you'll notice that it's pointing to "app.js", and not "app.12ab34.js". We're not using hashes because we don't want to update the base application each time the micro-frontend changes. Instead, we are returning a Cache-Control header to prevent any browser caching of the micro-frontend.
This also is not ideal, because while we gain our independence, we lose the caching of our micro-frontend code.
So, my question: if we were to enable hashes in the filenames on the micro-frontends, is there a way that the base application can be set up where we won't have to update it for hash changes? To put it differently, is there a completely different way of connecting these apps that I haven't thought of yet?