What if you want to publish a change to the header, an already have fifty pages using that? You would have to ask every page to upgrade it's version of header, meanwhile, your users would get inconsistent headers across the website
You are now compiling another app as part of yours, what if it throws something unexpected, will your app break too?
You are forced to have the same technologies on both sides, what if header the header uses clojurescript and your page uses elm? Poor webpack, it now has to understand it all when compiling.
but at the end, they all need to integrate somehow in the same front-end so the user can see it.
Contract Testing 也只不过是在微服务架构下的产物,很多都是。
第三方模块重叠 / 冗余组成复杂性
依赖管理
At first, we built applications as completely standalone applications that were loaded into iframes and communicated over postmessage. We're still doing that for some things, but it has some big drawbacks, especially when it comes to bundle size and browser support. Bundle size is pretty obvious, since you end up sending the same libraries multiple times, and since the applications are separated, you can't extract common dependencies at build time.
The problem of extracting libraries out is the synchronization between the page and the apps, you don't want to load any more or any less libraries that your apps need, so let's just focus on the main, heavier ones, such as React for now.
Problem: Some apps may take longer to load
There are some cases where things take a while to load on the back-end, maybe your header loads much faster than the other parts, and you want to display that ASAP to your users, while the products list takes more time.
This basically loads the apps through ajax and insert their content inside those divs. It also has to clone each script tag manually for them to work.
var script = document.createElement("script");
script.setAttribute("src", nonExecutableScript.src);
script.setAttribute("type", "text/javascript");
element.appendChild(script);
一个缺点:to avoid problems with Javascript and CSS loading order, I suggest you to evolve this to a solution similar to facebook's bigpipe, returning a JSON like
{ html: ..., css: [...], js: [...] } so you can have full control of it.
Public Path Problem and Routing
coupling between the homepage and the apps, what if one team takes care of developing the homepage, and another one the header? What if we want to add the same header to another page?
a centralized URLs service. It should provide an API for the apps to register their own URLs, and this service would be in the front of your website, just pointing to the other apps. We will call it Router.
because it should work with any other technologies and frameworks, you can send messages from React to Angular for example.
This is the same reason nowadays everybody uses JSON to communication on the back-end, even if nobody uses NodeJS!
how do we test this communication? How to write integration or contract tests here? I don't know. Also adding some ideas from Event Driven Architecture here might be good.
WebComponents are still not fully supported in all browsers, with Mozilla holding back HTML imports, so you will need polyfills, more code for the user to load.
It haven't really gained popularity yet, maybe never will, I see blogposts from 2013 and still few people have tried it!
JavaScript bundle has to load first and register the components in order for the DOM to load, which means that to gain the advantages of server-side rendering you'll probably need to be more clever.
For this alternative we had to make changes not only on the homepage, but on the apps too, to convert them to WebComponents.