Rails 4的Asset-Pipeline / Turbolinks对于大型应用程序的优缺点是什么?

时间:2022-10-27 02:08:54

We're working on a pretty big and wide application. The website will have a lot of different sections with some very different user interface requirements and behaviors.

我们正在开发一个相当广泛的应用程序。该网站将有许多不同的部分,具有一些非常不同的用户界面要求和行为。

Looking into the future, Rails 4 separated the asset pipeline into a separated gem so we can choose to include it or not. The same thing might happen with turbolinks.

展望未来,Rails 4将资产管道分离为一个独立的宝石,以便我们可以选择是否包含它。 turbolinks可能会发生同样的事情。

The question I keep asking myself these days and can't find an answer is: should I use theses libraries in our project or not ?

这些天我一直在问自己但无法找到答案的问题是:我应该在项目中使用这些库吗?

The main issues in my reflection is the fact that the all-in-one file strategy will probably not work and we'll have to use file bundles in the different parts of the application. How is turbolinks going to react with this, because it must assume that all the js/css is already loaded ? Does the advantages of such a configuration overcome the code complexity implied by both the pipeline and turbolinks ?

我反思的主要问题是,一体化文件策略可能不起作用,我们将不得不在应用程序的不同部分使用文件包。 turbolink会如何对此作出反应,因为它必须假设所有js / css已经加载?这种配置的优势是否克服了管道和turbolinks所隐含的代码复杂性?

I do not expect a Yes/No answer, just some opinions about the matter.

我不指望是/否答案,只是对此事的一些看法。

2 个解决方案

#1


11  

Both are valid tools which do not necessarily cancel each other out.

两者都是有效的工具,不一定互相抵消。

Turbolinks: Enables you to load only the body of a page, thus making it work as an AJAX request (an example of such a behaviour would be the one Facebook has).

Turbolinks:允许您仅加载页面的主体,从而使其作为AJAX请求工作(这种行为的一个例子就是Facebook拥有的)。

Advantages:

优点:

  • Skips the browser task of fully rendering a new page, thus eliminating the "blank page" time where the browser is unresponsive.
  • 跳过完全呈现新页面的浏览器任务,从而消除了浏览器无响应的“空白页面”时间。
  • Related with previous: In case you are having behaviour that might get affected by loading a new page, like let's say, playing a song, turbolinks will not affect it (see soundcloud next).
  • 与上一篇相关:如果您的行为可能会受到加载新页面的影响,比如说,播放一首歌曲,则turbolinks不会影响它(请参阅下面的soundcloud)。
  • Doesn't reload the document head, therefore not loading the same tags/content twice (if it is the same).
  • 不重新加载文档头,因此不加载相同的标记/内容两次(如果它是相同的)。
  • Enables you to still cache view content on the server side.
  • 使您仍然可以在服务器端缓存视图内容。

Disadvantages:

缺点:

  • A drag if header tags really need to be updated (new js files, new css files, metatags update...)
  • 拖动if标头标签确实需要更新(新的js文件,新的css文件,元标记更新......)
  • If you want to use client-side view rendering, it is just not the tool for it.
  • 如果您想使用客户端视图呈现,那么它就不是它的工具。
  • The default-behaviour to disable the behaviour is just painful (using css classes to disable anchor tags inside a section? that just sucks).
  • 禁用行为的默认行为是痛苦的(使用css类来禁用部分内的锚标记?这很糟糕)。

It's actually a question of what the architecture of your app is, what does it target.

这实际上是一个问题,即你的应用程序的架构是什么,它的目标是什么。

About asset pipelining, I have had mixed results with it, even though I'd say it has more advantages than disadvantages. Overall, pre-processing tools enhance cross-browser development productivity, but don't rely on it in production. But in the case of asset pipelining, it has to do as well with what you want it for. You can pre-process SASS, Coffeescript, you have great libraries like compass or bourbon, but this can also increase your performance overhead. So, benchmark it and see whether these should be tools for you.

关于资产流水线技术,我的结果好坏参半,尽管我说它有更多优点而不是缺点。总的来说,预处理工具可以提高跨浏览器的开发效率,但不会在生产中依赖它。但在资产流水线的情况下,它必须与你想要的一样。你可以预处理SASS,Coffeescript,你有很棒的图书馆,如指南针或波本威士忌,但这也会增加你的性能开销。因此,对它进行基准测试,看看它们是否适合您。

#2


2  

Let's start with a post about the drawbacks: http://eviltrout.com/2013/01/06/turbolinks-and-the-prague-effect.html

让我们从一篇关于缺点的帖子开始:http://eviltrout.com/2013/01/06/turbolinks-and-the-prague-effect.html

If this isn't a problem for you: http://geekmonkey.org/2012/09/introducing-turbolinks-for-rails-4-0/

如果这对您来说不是问题:http://geekmonkey.org/2012/09/introducing-turbolinks-for-rails-4-0/

To wrap things up: Turbolinks will improve your page load significantly if your pages share JavaScript and CSS styling. PJAX comes in handy, when server-side performance is an issue.

总结一下:如果您的页面共享JavaScript和CSS样式,Turbolinks将显着改善您的页面加载。当服务器端性能成为问题时,PJAX就派上用场了。

  • Hope this helps :)
  • 希望这可以帮助 :)

#1


11  

Both are valid tools which do not necessarily cancel each other out.

两者都是有效的工具,不一定互相抵消。

Turbolinks: Enables you to load only the body of a page, thus making it work as an AJAX request (an example of such a behaviour would be the one Facebook has).

Turbolinks:允许您仅加载页面的主体,从而使其作为AJAX请求工作(这种行为的一个例子就是Facebook拥有的)。

Advantages:

优点:

  • Skips the browser task of fully rendering a new page, thus eliminating the "blank page" time where the browser is unresponsive.
  • 跳过完全呈现新页面的浏览器任务,从而消除了浏览器无响应的“空白页面”时间。
  • Related with previous: In case you are having behaviour that might get affected by loading a new page, like let's say, playing a song, turbolinks will not affect it (see soundcloud next).
  • 与上一篇相关:如果您的行为可能会受到加载新页面的影响,比如说,播放一首歌曲,则turbolinks不会影响它(请参阅下面的soundcloud)。
  • Doesn't reload the document head, therefore not loading the same tags/content twice (if it is the same).
  • 不重新加载文档头,因此不加载相同的标记/内容两次(如果它是相同的)。
  • Enables you to still cache view content on the server side.
  • 使您仍然可以在服务器端缓存视图内容。

Disadvantages:

缺点:

  • A drag if header tags really need to be updated (new js files, new css files, metatags update...)
  • 拖动if标头标签确实需要更新(新的js文件,新的css文件,元标记更新......)
  • If you want to use client-side view rendering, it is just not the tool for it.
  • 如果您想使用客户端视图呈现,那么它就不是它的工具。
  • The default-behaviour to disable the behaviour is just painful (using css classes to disable anchor tags inside a section? that just sucks).
  • 禁用行为的默认行为是痛苦的(使用css类来禁用部分内的锚标记?这很糟糕)。

It's actually a question of what the architecture of your app is, what does it target.

这实际上是一个问题,即你的应用程序的架构是什么,它的目标是什么。

About asset pipelining, I have had mixed results with it, even though I'd say it has more advantages than disadvantages. Overall, pre-processing tools enhance cross-browser development productivity, but don't rely on it in production. But in the case of asset pipelining, it has to do as well with what you want it for. You can pre-process SASS, Coffeescript, you have great libraries like compass or bourbon, but this can also increase your performance overhead. So, benchmark it and see whether these should be tools for you.

关于资产流水线技术,我的结果好坏参半,尽管我说它有更多优点而不是缺点。总的来说,预处理工具可以提高跨浏览器的开发效率,但不会在生产中依赖它。但在资产流水线的情况下,它必须与你想要的一样。你可以预处理SASS,Coffeescript,你有很棒的图书馆,如指南针或波本威士忌,但这也会增加你的性能开销。因此,对它进行基准测试,看看它们是否适合您。

#2


2  

Let's start with a post about the drawbacks: http://eviltrout.com/2013/01/06/turbolinks-and-the-prague-effect.html

让我们从一篇关于缺点的帖子开始:http://eviltrout.com/2013/01/06/turbolinks-and-the-prague-effect.html

If this isn't a problem for you: http://geekmonkey.org/2012/09/introducing-turbolinks-for-rails-4-0/

如果这对您来说不是问题:http://geekmonkey.org/2012/09/introducing-turbolinks-for-rails-4-0/

To wrap things up: Turbolinks will improve your page load significantly if your pages share JavaScript and CSS styling. PJAX comes in handy, when server-side performance is an issue.

总结一下:如果您的页面共享JavaScript和CSS样式,Turbolinks将显着改善您的页面加载。当服务器端性能成为问题时,PJAX就派上用场了。

  • Hope this helps :)
  • 希望这可以帮助 :)