关于reactjs:反应引擎与其他模板引擎

react-engine vs other template engines

我想知道使用Paypal的React Engine(https://github.com/paypal/react-engine),但我有一些疑问:

与其他模板引擎(如把手)相比有什么好处?

为什么要上传.jsx文件而不上传(jsx预编译/转换).js文件? (这应该更快,因为不必在服务器上处理转换)。

我一直在研究,但感到困惑。

谢谢


react-engine与模板引擎之间的主要区别仅在于浏览器使用户能够与浏览器页面进行交互时。但是,机器如何访问单个数据很重要。

假设我们要运行一个简单的网页。只是滚动和打开文本信息。通常,使用模板引擎(例如Handlebars.js),当浏览器请求到达服务器时,它会尝试弄清楚如何响应以及该怎么做。也就是说,模板引擎可以引用从存储到本地可访问源中的文件中提取的现有数据。它们正在加载有关网站模板文件的所有已定义数据(即headmetatitle等),并带有不完整的HTML字符串。然后将此HTML发送回浏览器并进行呈现。

react-engine,在同一侧,它使用相同的呈现机制。但是,它不是使用模板引擎语义,而是使用JSX,或者,如果需要,也可以使用JavaScript。因此,JSX比模板引擎更广泛。 Hajime Yamasaki Vukelic的一篇很棒的文章从JSX和HTML模板之间的不同angular论述了关注点的分离。

With template engines, you feed the library a string (usually but not
necessarily HTML), which is then converted into a piece of JavaScript
code which generates virtual DOM structures when executed. At design
time, templates are just strings, so we dona€?t have direct access to
the surrounding code. For instance, we cana€?t import helper functions,
or call methods. These things are only possible through abstractions
called directives (and possibly other names depending on where you are
coming from). Directives are the glue between the HTML and the
JavaScript.

到目前为止,两种解决方案之间都没有相关的区别。指向下一个或上一个简单网页的链接只是简单的Next元素。

目前,当我们决定实现一些交互时,react-engine将是赢家。虽然react-engine渲染不需要JavaScript在客户端运行,但它将通过搜索启用SEO。

模板引擎也具有此SEO支持,但影响较小。我们不能在这里全部运行JavaScript来呈现HTML。甚至jQuery之类的库也需要对浏览器窗口对象的实时访问,而这在服务器端无法轻易模拟。因此,模板引擎的生产率下降。

最后,模板引擎可以执行与react-engine渲染相同的操作。也许不那么容易或不那么快,但是两种工具都是合格的。您还可以阅读有关此主题的另一篇精彩文章。