简体   繁体   English

Aurelia:同构?

[英]Aurelia: Isomorphic?

As far as I know, Aurelia does not support server-side rendering as mentioned here . 据我所知,Aurelia不支持这里提到的服务器端渲染。

But the question is: is it possible to do this with some hacks/workarounds? 但问题是:是否有可能通过一些黑客/解决方法来做到这一点?

The most obvious idea would be to use Phantom, Nightmare.js or whatever to simply render that page in Chrome on server and serve that to client, but this is very likely to cause big productivity issues. 最明显的想法是使用Phantom,Nightmare.js或其他任何东西来简单地在服务器上的Chrome中呈现该页面并将其提供给客户端,但这很可能会导致很大的生产力问题。

Thanks! 谢谢!

UPD UPD

According to Rob Eisenberg's response on FDConf today (16 Apr 2016), server-side rendering will be implemented in 2016, there's one core team member working on that and there's a deadline for this feature. 根据Rob Eisenberg今天(2016年4月16日)对FDConf的回应,服务器端渲染将在2016年实施,有一个核心团队成员正在研究这个,并且这个功能有截止日期。

There is an open issue for Universal/Isomorphic Aurelia which you can monitor. Universal / Isomorphic Aurelia有一个可以监控的未解决的问题 In particular EisenbergEffect (who is Rob Eisenberg, the creator of Aurelia) states that they are gradually working towards providing Universal support for Aurelia. 尤其是EisenbergEffect(Aurelia的创建者Rob Eisenberg)表示他们正在逐步为Aurelia提供Universal支持。 This post from him provides most of the detail: 他发表的这篇文章提供了大部分细节:

EisenbergEffect commented on Aug 25 EisenbergEffect于8月25日发表评论

We are trying to lock things down within the next month. 我们正试图在下个月内锁定事情。 That doesn't mean we won't add anything after that, but we need to work towards stabilization, performance and solid documentation without distractions of lots of new features for a little bit. 这并不意味着我们之后不会添加任何内容,但我们需要努力实现稳定性,性能和可靠的文档,而不会分散许多新功能。

Primarily, "isomorphism" isn't a use case we want to tackle for the initial v1 release. 首先,“同构”不是我们想要解决的初始v1版本的用例。 Again, that doesn't mean we won't do it later. 同样,这并不意味着我们以后不会这样做。 But, we want to have a solid framework for browser-based apps as well as phone gap and electron/nwjs desktop apps first. 但是,我们希望首先为基于浏览器的应用程序以及手机差距和电子/ nwjs桌面应用程序提供可靠的框架。 That was our original goal and we want to make sure we handle those scenarios better than any other framework or library. 这是我们最初的目标,我们希望确保比任何其他框架或库更好地处理这些场景。

After that, we've got some other features we want to do, which are valuable in their own right, but will also take us closer to isomorphism. 在那之后,我们还有其他一些我们想做的功能,这些功能本身就很有价值,但也会让我们更接近于同构。

  1. Enable all aurelia libraries to run on the server. 启用所有aurelia库以在服务器上运行。 This enables some new testing scenarios, so it's valuable if only from that perspective. 这可以实现一些新的测试场景,因此只有从这个角度来看它才有价值。
  2. Once code can run on the server, we can then implement server view compilation. 一旦代码可以在服务器上运行,我们就可以实现服务器视图编译。 This isn't isomorphic rendering, but rather the ability to run Aurelia's view compiler as part of your build and bundle process. 这不是同构渲染,而是在构建和捆绑过程中运行Aurelia视图编译器的能力。 This enables more work to be done ahead of time, as part of your build, and then it doesn't need to be done in the browser at runtime. 这使得可以提前完成更多工作,作为构建的一部分,然后不需要在运行时在浏览器中完成。 So, this will improve the startup time for all apps and reduce initial render times for all components. 因此,这将改善所有应用程序的启动时间并减少所有组件的初始渲染时间。 It also will make it possible to store compiled views in browser local cache to improve performance of successive runs of the application. 它还可以将编译视图存储在浏览器本地缓存中,以提高应用程序连续运行的性能。
  3. After both of those things are in place, then we can look at doing a full server render for each route. 在这两件事都到位后,我们可以看看为每条路线做一个完整的服务器渲染。 This isn't quite isomorphic in the truest sense, but it solves the SEO problem without needing 3rd party libraries. 这在最真实的意义上并不完全同构,但它解决了SEO问题,而不需要第三方库。 So, it's nice to have a solution there. 所以,在那里找到解决方案真好。
  4. Finally, we can then "sync" a server pre-rendered app with a stateful Aurelia app running in browser, giving us 100% isomorphic support. 最后,我们可以将服务器预呈现的应用程序与在浏览器中运行的有状态Aurelia应用程序“同步”,为我们提供100%的同构支持。 So, those are the stages. 那么,那些是阶段。 The first two would be beneficial to all developers, even those who are not interested in isomorphic apps. 前两个对所有开发人员都有好处,即使那些对同构应用程序不感兴趣的开发人员也是如此。 The 3rd stage can be done today with 3rd party libraries, so this is a nice to have for us, for those who don't want an extra dependency. 今天的第三阶段可以通过第三方库来完成,所以对于那些不想要额外依赖的人来说,这对我们来说是一件好事。 All of that leads into 4 which adds the final pieces. 所有这一切都导致4增加最后的部分。

We have already begun some of the work on 1. That might get into our first release. 我们已经开始了一些关于1的工作。这可能会进入我们的第一个版本。 We aren't going to push it, but it's already in progress and we're looking for the problem areas so we can make it work. 我们不会推动它,但它已经在进行中,我们正在寻找问题区域,以便我们可以使它工作。 Steps 2-4 involve significant work. 步骤2-4涉及重要工作。 Really, we are talking about a collection of features here, each one being rather complex. 真的,我们在这里讨论的是一系列功能,每个功能都相当复杂。 So, those will probably come in stages after v1, as point releases. 因此,这些可能会在v1之后分阶段进行,作为点发布。

We really don't want to do what Angular 2 has done. 我们真的不想做Angular 2所做的事情。 They have massively complicated their architecture...to the point that very few people will be able to understand it and developing applications with it has become much more complicated, with many nuances. 他们的架构大规模复杂化......以至于很少有人能够理解它并且用它开发应用程序变得更加复杂,有许多细微差别。 We really don't want that, so we're focusing on the developer experience we want first, then we'll come back and see about isomorphic support (yes, we already have ideas how to do this cleanly, but want to give those ideas some time to mature). 我们真的不希望这样,所以我们首先关注我们想要的开发者体验,然后我们会回来看看同构支持(是的,我们已经有了如何干净利落地想法,但想要给那些一段时间成熟的想法)。 In all of this, our goal is to be modular. 在所有这些中,我们的目标是模块化。 So, if you don't care about isomorphism, you don't have to think or worry about it. 所以,如果你不关心同构,你就不必去思考或担心它。 If you do, you would install the necessary packages, agree to the "constraints" of the system and be on your way. 如果你这样做,你将安装必要的软件包,同意系统的“约束”,并在你的路上。

So, to all who are interested in this topic, I would just ask you kindly to be patient. 所以,对于所有对这个话题感兴趣的人,我会请你耐心等待。 For those who aren't interested in isomorphism, don't worry, we aren't going to brake the developer experience on you. 对于那些对同构不感兴趣的人,不要担心,我们不会扼杀开发者的经验。 For those of you who want it badly, you will have to wait longer and it will come in stages and in modular pieces so as not to disrupt others. 对于那些想要它的人,你将不得不等待更长时间,它将分阶段和模块化的部分,以免扰乱他人。

Just for now 就在现在

The only way I can propose: render pages with phantomjs + use redis to speedup that process. 我可以建议的唯一方法:使用phantomjs渲染页面+使用redis加速该过程。

But you will have lots of trouble restoring the state at client side. 但是在客户端恢复状态会有很多麻烦。

....... .......

Dirty solution 脏的解决方案

Load rendered page from server and at the client side render new one in the usual way, than switch UI's. 从服务器和客户端加载呈现的页面以通常的方式呈现新的页面,而不是切换UI。

It won't be a truly isomorphic, but something like https://github.com/rails/turbolinks on first page load. 它不会是真正的同构,但首页加载时会像https://github.com/rails/turbolinks

..... .....

I hope soon Aurelia team will provide simpler stuff for that case. 我希望很快Aurelia团队能为这个案例提供更简单的东西。

In the current Aurelia there is the possibility to enhance existing html. 在目前的Aurelia中,有可能增强现有的html。 The document says 该文件说

So far you've seen Aurelia replacing a portion of the DOM with a root component. 到目前为止,您已经看到Aurelia用根组件替换了DOM的一部分。 However, that's not the only way to render with Aurelia. 但是,这不是用Aurelia渲染的唯一方法。 Aurelia can also progressively enhance existing HTML. Aurelia还可以逐步增强现有的HTML。

Check out enhancement section @ http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.0.8/doc/article/app-configuration-and-startup 查看增强部分@ http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.0.8/doc/article/app-configuration-and-startup

I'm looking forward to get a better documentation of this feature. 我期待着能够更好地记录这个功能。 It seems to me like rendering the html on the Server and inject aurelia will work with it and google will like it as well. 在我看来,在服务器上渲染html并注入aurelia将使用它,谷歌也会喜欢它。

a hack i just came up with is to put a static copy of the initial rendering into the index.html file: 我刚刚提出的一个黑客攻击是将初始渲染的静态副本放入index.html文件中:

<html>
  <body aurelia-app="main">
    <h1>static copy of the website here</h1>
    <script src="scripts/vendor-bundle.js" data-main="aurelia-bootstrapper"></script>
  </body>
</html>

this is of course completely manual and if the initial rendering contains any content from a database then the static copy may need to be updated every time the database content changes. 这当然是完全手动的,如果初始呈现包含来自数据库的任何内容,则每次数据库内容更改时都可能需要更新静态副本。 (which is of course what isomorphic rendering is supposed to solve) (这当然是什么同构渲染应该解决)

however for my needs, which is a simple website with some information that is rarely updated, this solution is good enough. 但是对于我的需求,这是一个简单的网站,其中包含一些很少更新的信息,这个解决方案已经足够了。 it will at least suffice until i am able to implement proper isomorphic rendering. 它至少就足够了,直到我能够实现正确的同构渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM