前段时间,我无意中看到了一个新框架:Fresh。宣称是下一代 Web 框架。它列举了很多功能亮点,随便看了几眼没太在意,但有一段话成功的吸引了我:
The single biggest architecture decision that Fresh makes is its usage of the islands architecture pattern. This means that Fresh applications ship pure HTML to the client by default. Parts of server-rendered page can then be independently re-hydrated with interactive widgets (islands). This means that the client is only responsible for rendering parts of the page that are interactive enough to warrant the extra effort. Any content that is purely static does not have related client-side JavaScript and is thus very lightweight.
简单理解就是:Fresh 使用了 Islands Architecture,程序响应给客户端的都是纯 HTML,然后,通过可交互的 widgets 对 SSR 的部分内容进行水化(re-hydrated),静态的部分不需要任何 JS 代码。—— 简直是完美!!
为何这么说呢?这还得从性能优化和 SSR 讲起...