With Webpack 5 module federation if remote entry is modified, you don't need to redeploy main module/application and the newest version of the module will be loaded when it's requested by the browser.
I'm wondering: since the remote URL remains the same (e.g. http://localhost:8081/remoteEntry.js
), the browser probably will cache the file and cached version loaded every time you load the main module. On the other hand, if you add cache busting for remote entries, you will not have caching.
Let's assume that there is an application with micro-frontend architecture using Webpack 5 Module federation. There is a remote micro frontend with a config like:
output: {
publicPath: "http://localhost:8081/",
},
plugins: [
new ModuleFederationPlugin({
name: "app1",
filename: "remoteEntry.js",
exposes: {
"./Component1": "./src/Component1",
"./someModule1": "./src/someModule1",
},
})
]
and then main module config:
output: {
publicPath: "http://localhost:8080/",
},
plugins: [
new ModuleFederationPlugin({
name: "mainApp",
filename: "remoteEntry.js",
remotes: {
app1: "app1@http://localhost:8081/remoteEntry.js"
}
})
]
Both modules are deployed on production.
Then I change Component1
from app1
and deploy app1
module.
How to deal with remote modules caching?
UPDATE:
It looks like in my case the browser uses heuristic caching (https://www.rfc-editor.org/rfc/rfc7234#section-4.2.2) for remoteEntry.js
since the server doesn't provide explicit expiration times.
Thus, when remoteEntry.js
updates, the main application still loads this file from the cache that could be cached for weeks.
For chunks, it's not a problem since webpack could be configured to include hash in the file names.
For remoteEntry.js
I see 2 options:
- cache-busting
- explicitly specify cache control
Do you think it's a way to go?