决定使用客户端代码有多大

时间:2022-02-20 03:50:18

I'm developing a site which will have a fairly extensive admin section. The front end is fairly simple, and doesn't need a complex UI at all, so I don't intend to have too much client side code there.

我正在开发一个具有相当广泛的管理部分的网站。前端非常简单,根本不需要复杂的UI,所以我不打算在那里有太多的客户端代码。

I'm trying to figure out at this stage how much logic to place on the client side for the admin section. I'm using Ruby on Rails - as one extreme, I could generate the admin pages entirely server side and use extremely light client side code for some basic enhancements. At the other extreme, I could use a framework like AngularJS to make a single page application for the admin section, communicating with the server by JSON.

我想在这个阶段弄清楚管理部分在客户端放置了多少逻辑。我正在使用Ruby on Rails - 作为一个极端,我可以完全在服务器端生成管理页面,并使用极轻的客户端代码进行一些基本的增强。在另一个极端,我可以使用像AngularJS这样的框架为admin部分创建单个页面应用程序,通过JSON与服务器通信。

The main disadvantage I see for the extreme client side approach is that there will be a significant initial page load time, and it'll feel heavy on mobile devices. The advantages I see are that it'll be far more responsive after the initial load, and that the application on the server will be purely an API, and easy to extend or use in other ways should the need arise.

我看到的极端客户端方法的主要缺点是会有一个重要的初始页面加载时间,并且它会在移动设备上感到沉重。我看到的优点是它在初始加载后响应性更强,并且服务器上的应用程序将纯粹是一个API,并且在需要时可以以其他方式扩展或使用。

I saw this article about how basecamp manages to be fast and responsive with minimal client side code. While they talk about how they achieved their speed improvements, they don't mention their reasons for sticking with heavily server side code.

我看到这篇文章关于basecamp如何通过最少的客户端代码来快速响应。当他们谈论他们如何实现速度提升时,他们没有提到他们坚持使用大量服务器端代码的原因。

So how do I settle on the right balance between client side and server side code? I'd really appreciate any insights into this, pros and cons I have not considered, and resources I could look into. Thanks!

那么我如何在客户端和服务器端代码之间找到适当的平衡点呢?我非常感谢对此的任何见解,我没有考虑的利弊,以及我可以研究的资源。谢谢!

1 个解决方案

#1


5  

This is a really interesting topic, and I guess a lot of developers are asking themselves the same question.

这是一个非常有趣的话题,我想很多开发人员都在问自己同样的问题。

First of all it really depends on the project at hand. But here are some points that may help you with your decision.

首先,它真的取决于手头的项目。但是这里有一些可以帮助您做出决定的要点。

The UI

If your application will have a complex user interface with a lot of user interaction (clicking, dragging etc) and is supposed to "feel responsive" and more like a desktop application I think the client-side approach is the right choice.

如果您的应用程序将具有复杂的用户界面,并且具有大量用户交互(点击,拖动等)并且应该“感觉响应”并且更像桌面应用程序,我认为客户端方法是正确的选择。

However you said:

不过你说:

The front end is fairly simple, and doesn't need a complex UI at all, so I don't intend to have too much client side code there.

前端非常简单,根本不需要复杂的UI,所以我不打算在那里有太多的客户端代码。

Rails and Development Experience

It seems like DHH and therefore by extension Rails is not that interested in the client-heavy approach.

看起来像DHH,因此通过扩展Rails对客户端繁重的方法不感兴趣。

You have to remember that Rails originated from Basecamp and the recent features (introduced in Rails 4: like russian doll caching and turbo links) were developed for Basecamp. If you look at the UI for the new version one is able to see the reasoning behind these features, however not every application and user interface fit this document-centric model. So take the impressive results from 37signals (and for that matter all performance related figures) with a grain of salt (e.g. the caching hardware they use is incredible and not everyone is able to afford such a setup).

你必须记住Rails起源于Basecamp,最近的功能(在Rails 4中引入:像俄罗斯娃娃缓存和turbo链接)是为Basecamp开发的。如果您查看新版本的UI,可以看到这些功能背后的原因,但并非每个应用程序和用户界面都适合这种以文档为中心的模型。因此,从37signals(以及所有与性能相关的数据)中获得令人印象深刻的结果(例如,他们使用的缓存硬件是令人难以置信的,并非每个人都能够负担得起这样的设置)。

Also remember that angular and ember are fairly young projects and (especially ember) are going through a lot of (potentially breaking) changes which may result in frustrating api fixes.

还记得angular和ember是相当年轻的项目,并且(特别是ember)正在经历许多(可能破坏)更改,这可能导致令人沮丧的api修复。

Also ask yourself, what development environment do you prefer?

还要问问自己,您更喜欢哪种开发环境?

The Ruby/Serverside development style with TDD and RSpec and fast feedback loops, compared to debugging in the browser and writing Javascript. (Although projects like the Ember Inspector are making great progress and improve the experience.) Don't underestimate this point as you will be spending a lot of time in these environments.

与在浏览器中调试和编写Javascript相比,Ruby / Serverside开发风格具有TDD和RSpec以及快速反馈循环。 (尽管像Ember Inspector这样的项目正在取得很大的进步并改善了体验。)不要低估这一点,因为你将在这些环境中花费大量时间。

Speed

Like DHH mentions in his article, they were able to achieve fantastic results with more traditional, server side methods.

就像DHH在他的文章中提到的那样,他们能够通过更传统的服务器端方法获得梦幻般的结果。

I think you cannot get a scientific result without writing the same application for both architectures and do some performance testing for each.

我认为如果不为两种体系结构编写相同的应用程序并为每种体系结构进行一些性能测试,就无法获得科学结果。

This is of course an ideal and unrealistic scenario, but I also think it isn't even needed: It comes down to the UI and the perceived speed/performance of your application. If you have a "one-page" UI where the user is mostly busy on one page :) the client-side approach will probably be perceived as "snappier" and the initial performance hit from downloading the javascript will be made up for.

这当然是一个理想且不切实际的场景,但我也认为它甚至不需要:它归结为UI和应用程序的感知速度/性能。如果你有一个“单页”用户界面,用户主要忙于一个页面:)客户端方法可能会被视为“更快”,下载javascript的初始性能将被弥补。

Api

If you are planning to write a good json API for your application, there is a good argument to be made for the client side approach. eviltrout:

如果您打算为您的应用程序编写一个好的json API,那么就可以为客户端方法提出一个很好的论据。 eviltrout:

One amazing side effect of a rich client side app is you end up with a battle tested API. Our app has consumed our own API since day one, so we know it works.

富客户端应用程序的一个惊人的副作用是你最终得到一个经过测试的API。我们的应用程序从第一天开始就使用了我们自己的API,所以我们知道它有效。

References/Reading/Watching

People/Projects you can follow:

您可以关注的人/项目:

Again, it depends on what kind project you are undertaking. If it is a less serious application and you are curious about new technologies and client side frameworks like ember and angular, and you want to tinker with them: I would totally go for it.

同样,这取决于您正在进行的项目类型。如果它是一个不太严肃的应用程序,你对新技术和客户端框架如ember和angular很好奇,你想修补它们:我会完全去做。

This a very "hot" topic at the moment, and for the years to come and I'm very interested in how it will all work out. Hope this helps a little.

这是一个非常“热门”的话题,对于未来几年,我对它将如何发挥作用非常感兴趣。希望这有所帮助。

#1


5  

This is a really interesting topic, and I guess a lot of developers are asking themselves the same question.

这是一个非常有趣的话题,我想很多开发人员都在问自己同样的问题。

First of all it really depends on the project at hand. But here are some points that may help you with your decision.

首先,它真的取决于手头的项目。但是这里有一些可以帮助您做出决定的要点。

The UI

If your application will have a complex user interface with a lot of user interaction (clicking, dragging etc) and is supposed to "feel responsive" and more like a desktop application I think the client-side approach is the right choice.

如果您的应用程序将具有复杂的用户界面,并且具有大量用户交互(点击,拖动等)并且应该“感觉响应”并且更像桌面应用程序,我认为客户端方法是正确的选择。

However you said:

不过你说:

The front end is fairly simple, and doesn't need a complex UI at all, so I don't intend to have too much client side code there.

前端非常简单,根本不需要复杂的UI,所以我不打算在那里有太多的客户端代码。

Rails and Development Experience

It seems like DHH and therefore by extension Rails is not that interested in the client-heavy approach.

看起来像DHH,因此通过扩展Rails对客户端繁重的方法不感兴趣。

You have to remember that Rails originated from Basecamp and the recent features (introduced in Rails 4: like russian doll caching and turbo links) were developed for Basecamp. If you look at the UI for the new version one is able to see the reasoning behind these features, however not every application and user interface fit this document-centric model. So take the impressive results from 37signals (and for that matter all performance related figures) with a grain of salt (e.g. the caching hardware they use is incredible and not everyone is able to afford such a setup).

你必须记住Rails起源于Basecamp,最近的功能(在Rails 4中引入:像俄罗斯娃娃缓存和turbo链接)是为Basecamp开发的。如果您查看新版本的UI,可以看到这些功能背后的原因,但并非每个应用程序和用户界面都适合这种以文档为中心的模型。因此,从37signals(以及所有与性能相关的数据)中获得令人印象深刻的结果(例如,他们使用的缓存硬件是令人难以置信的,并非每个人都能够负担得起这样的设置)。

Also remember that angular and ember are fairly young projects and (especially ember) are going through a lot of (potentially breaking) changes which may result in frustrating api fixes.

还记得angular和ember是相当年轻的项目,并且(特别是ember)正在经历许多(可能破坏)更改,这可能导致令人沮丧的api修复。

Also ask yourself, what development environment do you prefer?

还要问问自己,您更喜欢哪种开发环境?

The Ruby/Serverside development style with TDD and RSpec and fast feedback loops, compared to debugging in the browser and writing Javascript. (Although projects like the Ember Inspector are making great progress and improve the experience.) Don't underestimate this point as you will be spending a lot of time in these environments.

与在浏览器中调试和编写Javascript相比,Ruby / Serverside开发风格具有TDD和RSpec以及快速反馈循环。 (尽管像Ember Inspector这样的项目正在取得很大的进步并改善了体验。)不要低估这一点,因为你将在这些环境中花费大量时间。

Speed

Like DHH mentions in his article, they were able to achieve fantastic results with more traditional, server side methods.

就像DHH在他的文章中提到的那样,他们能够通过更传统的服务器端方法获得梦幻般的结果。

I think you cannot get a scientific result without writing the same application for both architectures and do some performance testing for each.

我认为如果不为两种体系结构编写相同的应用程序并为每种体系结构进行一些性能测试,就无法获得科学结果。

This is of course an ideal and unrealistic scenario, but I also think it isn't even needed: It comes down to the UI and the perceived speed/performance of your application. If you have a "one-page" UI where the user is mostly busy on one page :) the client-side approach will probably be perceived as "snappier" and the initial performance hit from downloading the javascript will be made up for.

这当然是一个理想且不切实际的场景,但我也认为它甚至不需要:它归结为UI和应用程序的感知速度/性能。如果你有一个“单页”用户界面,用户主要忙于一个页面:)客户端方法可能会被视为“更快”,下载javascript的初始性能将被弥补。

Api

If you are planning to write a good json API for your application, there is a good argument to be made for the client side approach. eviltrout:

如果您打算为您的应用程序编写一个好的json API,那么就可以为客户端方法提出一个很好的论据。 eviltrout:

One amazing side effect of a rich client side app is you end up with a battle tested API. Our app has consumed our own API since day one, so we know it works.

富客户端应用程序的一个惊人的副作用是你最终得到一个经过测试的API。我们的应用程序从第一天开始就使用了我们自己的API,所以我们知道它有效。

References/Reading/Watching

People/Projects you can follow:

您可以关注的人/项目:

Again, it depends on what kind project you are undertaking. If it is a less serious application and you are curious about new technologies and client side frameworks like ember and angular, and you want to tinker with them: I would totally go for it.

同样,这取决于您正在进行的项目类型。如果它是一个不太严肃的应用程序,你对新技术和客户端框架如ember和angular很好奇,你想修补它们:我会完全去做。

This a very "hot" topic at the moment, and for the years to come and I'm very interested in how it will all work out. Hope this helps a little.

这是一个非常“热门”的话题,对于未来几年,我对它将如何发挥作用非常感兴趣。希望这有所帮助。