何时实施Ajax的最佳实践?

时间:2021-09-13 21:14:36

In this Microsoft tutorial they implement Ajax in the final step: "Step 7. Implement Ajax"

在这个Microsoft教程中,他们在最后一步实现了Ajax:“步骤7.实现Ajax”

I know it's only a tutorial so it's kept simple but I have seen this idea elsewhere too, build the app and then sprinkle ajax where appropriate.

我知道它只是一个教程,所以它保持简单,但我也在其他地方看到了这个想法,构建应用程序,然后在适当的地方撒上ajax。

I implement ajax as I go but I am wondering what people feel is a best practice concerning this. Is it best to throw ajax on at the end or should you be implementing it as you go? Anyone ran into trouble one way or another?

我在去的时候实现了ajax,但我想知道人们认为这是一个最好的做法。是最好在最后抛出ajax,还是应该在你去的时候实现它?有人遇到过这样或那样的麻烦吗?

7 个解决方案

#1


5  

If your core user interactions will rely on Ajax (e.g., Google Docs), then you should implement those bits early.

如果您的核心用户交互将依赖于Ajax(例如,Google Docs),那么您应该尽早实现这些位。

Otherwise, if your core interactions rely instead on reliably storing and retrieving data, add Ajax last. This way, you force yourself and your team to test your app's behavior as if JavaScript were unavailable on your user's browser. In this instance, Ajax would be an extra layer of user interface goodness.

否则,如果您的核心交互依赖于可靠地存储和检索数据,则最后添加Ajax。通过这种方式,您可以强迫自己和您的团队测试您应用的行为,就像用户浏览器上的JavaScript不可用一样。在这种情况下,Ajax将是一个额外的用户界面良好层。

#2


3  

The argument for doing AJAX last is that you are much more likely to develop a site that degrades gracefully if you get it working without AJAX first.

最后做AJAX的论点是,如果你在没有AJAX的情况下让它工作,你就更有可能开发一个优雅降级的网站。

This does not matter to some people--I've seen (internal) sites designed for a specific version of a specific browser with a definite set of features turned on. But if it matters to you, it is much easier to add AJAX to a site that works well without it than it is to remove AJAX from a site that depends on it from the start.

这对某些人来说无关紧要 - 我已经看到(内部)网站专为特定浏览器的特定版本设计,并且打开了一组明确的功能。但是,如果它对您很重要,那么将AJAX添加到一个运行良好的站点要容易得多,而不是从一开始就依赖它的站点中删除AJAX。

#3


2  

What does 'as you go' mean ? I start with a design, and so it's very clear what the final product will be. So, yes, you need to know where the ajax stuff happens right from the beginning.

什么'你去'是什么意思?我从一个设计开始,因此很清楚最终产品将是什么。所以,是的,你需要知道ajax的东西从一开始就发生了什么。

#4


1  

I do it as I go, where it makes sense. It's rare that we have a complete design spec from day 1, so you have to make a descision sometimes.

我去的时候,它是有意义的。我们很少从第1天开始就有完整的设计规格,所以你有时候必须做出决定。

#5


1  

Ignoring the fact that you'd expect the requirement for Ajax to fall out of the user interface specification requirements (if you have such a thing), I'd think about implementing it (or implementing the hooks) sooner rather than later.

忽略这样一个事实,即您希望Ajax的要求超出用户界面规范要求(如果您有这样的事情),我会考虑尽快实现它(或实现挂钩)。

1) retro-fitting it to something that's been architected to return complete pages will not necessarily be straightforward

1)将其改造为已经构建以返回完整页面的东西并不一定是直截了当的

2) it'll potentially impact the deployment pattern of your solution, in that it'll be serving up pages plus page fragments/objects, and those fragments will result in many more hits to your server (imagine the extra hits that your server would get if you introduced something like Google Suggest, where potentially every keypress could result in a new server request).

2)它可能会影响你的解决方案的部署模式,因为它将提供页面加上页面片段/对象,这些片段将导致更多的服务器点击(想象一下你的服务器会有额外的点击量)如果你介绍像谷歌建议这样的东西,可能每个按键都可能导致新的服务器请求)。

So you may not want to implement the Ajaxness immediately. But I would urge you to consider it (and if its required) sooner rather than later.

所以你可能不想立即实现Ajaxness。但我会敦促你尽快考虑它(如果需要的话)。

#6


1  

Another argument for implementing Ajax early is that whenever you add any capability late in a project, you often have to tear down and rebuild some existing code or design to make it work. When you plan for the feature from the beginning, there's a lot less recoding required.

早期实现Ajax的另一个理由是,无论何时在项目后期添加任何功能,您都必须拆除并重建一些现有代码或设计才能使其正常工作。从一开始就计划使用该功能时,所需的重新编码要少得多。

#7


0  

In my opinion when it comes to ajax there are two camps. One camp wants to create this rich user experience with lots of neat UX goodies and will probably implement most of their sites features as ajax only. The other camp wants to add nice convenience features but the core of the project and most main features will be implemented server side. In the first camp where most of your features are going to be implemented in ajax I would work on the ajax early and work it into your design decision process upfront. For the second case I would implement all features server side and add the ajax afterwards to add some nice UX feel.

在我看来,当涉及到ajax时,有两个阵营。一个阵营希望通过许多简洁的用户体验好东西创建这种丰富的用户体验,并且可能只将其大部分网站功能实现为ajax。另一个阵营想要添加不错的便利功能,但项目的核心和大多数主要功能都将在服务器端实现。在第一个大部分功能将在ajax中实现的阵营中,我会尽早处理ajax并将其用于您的设计决策过程。对于第二种情况,我将实现所有功能服务器端,然后添加ajax以添加一些不错的UX感觉。

I remember reading early on with ajax, to implement your site like your user's browser did not have javascript, and then once all features are working add the ajax to improve the user experience. But since the early days of ajax Google has definitely pushed the envelope and a lot of people want to create these amazing rich user experiences on their websites with ajax. I've worked with a lot of people who really like to implement a lot of their features in ajax but few of them have had the chops to pull it off. I certainly don't have the chops myself and get very frustrated with buggy poorly tested features that look really cool... if you use them this certain way... cross your fingers. A lot of that has to do with testing, unit-testing is one thing, in browser testing is another and quite often I find myself working very hard just to get unit-tests in place let alone a whole in browser testing suite.

我记得早期用ajax阅读,实现你的网站就像你的用户的浏览器没有javascript,然后一旦所有功能都工作,添加ajax来改善用户体验。但是自从ajax的早期开始,Google肯定会推动这一局面,并且很多人希望在他们的网站上使用ajax创建这些惊人的丰富用户体验。我和很多人一起工作过,他们非常喜欢在ajax中实现很多功能,但很少有人能够实现这些功能。我当然没有自己的排骨,并且对于看起来非常酷的错误测试功能非常沮丧......如果你以某种方式使用它们......交叉你的手指。其中很多都与测试有关,单元测试是一回事,在浏览器测试中是另一回事,而且我经常发现自己非常努力只是为了让单元测试到位,更不用说整个浏览器测试套件了。

You have to decide what you want your user experience to be like, how ajax fits into those decision and then chose when to implement the ajax. Early for sites with major features implemented in ajax only, later for sites where ajax just addes UX sugar. That is my $0.02, I'm sure there is someone with the opposite opinion.

您必须决定您希望您的用户体验如何,ajax如何适应这些决定,然后选择何时实施ajax。对于仅在ajax中实现主要功能的网站而言,之前的早期版本仅适用于ajax仅添加UX糖的网站。这是我的0.02美元,我敢肯定有人有相反的意见。

#1


5  

If your core user interactions will rely on Ajax (e.g., Google Docs), then you should implement those bits early.

如果您的核心用户交互将依赖于Ajax(例如,Google Docs),那么您应该尽早实现这些位。

Otherwise, if your core interactions rely instead on reliably storing and retrieving data, add Ajax last. This way, you force yourself and your team to test your app's behavior as if JavaScript were unavailable on your user's browser. In this instance, Ajax would be an extra layer of user interface goodness.

否则,如果您的核心交互依赖于可靠地存储和检索数据,则最后添加Ajax。通过这种方式,您可以强迫自己和您的团队测试您应用的行为,就像用户浏览器上的JavaScript不可用一样。在这种情况下,Ajax将是一个额外的用户界面良好层。

#2


3  

The argument for doing AJAX last is that you are much more likely to develop a site that degrades gracefully if you get it working without AJAX first.

最后做AJAX的论点是,如果你在没有AJAX的情况下让它工作,你就更有可能开发一个优雅降级的网站。

This does not matter to some people--I've seen (internal) sites designed for a specific version of a specific browser with a definite set of features turned on. But if it matters to you, it is much easier to add AJAX to a site that works well without it than it is to remove AJAX from a site that depends on it from the start.

这对某些人来说无关紧要 - 我已经看到(内部)网站专为特定浏览器的特定版本设计,并且打开了一组明确的功能。但是,如果它对您很重要,那么将AJAX添加到一个运行良好的站点要容易得多,而不是从一开始就依赖它的站点中删除AJAX。

#3


2  

What does 'as you go' mean ? I start with a design, and so it's very clear what the final product will be. So, yes, you need to know where the ajax stuff happens right from the beginning.

什么'你去'是什么意思?我从一个设计开始,因此很清楚最终产品将是什么。所以,是的,你需要知道ajax的东西从一开始就发生了什么。

#4


1  

I do it as I go, where it makes sense. It's rare that we have a complete design spec from day 1, so you have to make a descision sometimes.

我去的时候,它是有意义的。我们很少从第1天开始就有完整的设计规格,所以你有时候必须做出决定。

#5


1  

Ignoring the fact that you'd expect the requirement for Ajax to fall out of the user interface specification requirements (if you have such a thing), I'd think about implementing it (or implementing the hooks) sooner rather than later.

忽略这样一个事实,即您希望Ajax的要求超出用户界面规范要求(如果您有这样的事情),我会考虑尽快实现它(或实现挂钩)。

1) retro-fitting it to something that's been architected to return complete pages will not necessarily be straightforward

1)将其改造为已经构建以返回完整页面的东西并不一定是直截了当的

2) it'll potentially impact the deployment pattern of your solution, in that it'll be serving up pages plus page fragments/objects, and those fragments will result in many more hits to your server (imagine the extra hits that your server would get if you introduced something like Google Suggest, where potentially every keypress could result in a new server request).

2)它可能会影响你的解决方案的部署模式,因为它将提供页面加上页面片段/对象,这些片段将导致更多的服务器点击(想象一下你的服务器会有额外的点击量)如果你介绍像谷歌建议这样的东西,可能每个按键都可能导致新的服务器请求)。

So you may not want to implement the Ajaxness immediately. But I would urge you to consider it (and if its required) sooner rather than later.

所以你可能不想立即实现Ajaxness。但我会敦促你尽快考虑它(如果需要的话)。

#6


1  

Another argument for implementing Ajax early is that whenever you add any capability late in a project, you often have to tear down and rebuild some existing code or design to make it work. When you plan for the feature from the beginning, there's a lot less recoding required.

早期实现Ajax的另一个理由是,无论何时在项目后期添加任何功能,您都必须拆除并重建一些现有代码或设计才能使其正常工作。从一开始就计划使用该功能时,所需的重新编码要少得多。

#7


0  

In my opinion when it comes to ajax there are two camps. One camp wants to create this rich user experience with lots of neat UX goodies and will probably implement most of their sites features as ajax only. The other camp wants to add nice convenience features but the core of the project and most main features will be implemented server side. In the first camp where most of your features are going to be implemented in ajax I would work on the ajax early and work it into your design decision process upfront. For the second case I would implement all features server side and add the ajax afterwards to add some nice UX feel.

在我看来,当涉及到ajax时,有两个阵营。一个阵营希望通过许多简洁的用户体验好东西创建这种丰富的用户体验,并且可能只将其大部分网站功能实现为ajax。另一个阵营想要添加不错的便利功能,但项目的核心和大多数主要功能都将在服务器端实现。在第一个大部分功能将在ajax中实现的阵营中,我会尽早处理ajax并将其用于您的设计决策过程。对于第二种情况,我将实现所有功能服务器端,然后添加ajax以添加一些不错的UX感觉。

I remember reading early on with ajax, to implement your site like your user's browser did not have javascript, and then once all features are working add the ajax to improve the user experience. But since the early days of ajax Google has definitely pushed the envelope and a lot of people want to create these amazing rich user experiences on their websites with ajax. I've worked with a lot of people who really like to implement a lot of their features in ajax but few of them have had the chops to pull it off. I certainly don't have the chops myself and get very frustrated with buggy poorly tested features that look really cool... if you use them this certain way... cross your fingers. A lot of that has to do with testing, unit-testing is one thing, in browser testing is another and quite often I find myself working very hard just to get unit-tests in place let alone a whole in browser testing suite.

我记得早期用ajax阅读,实现你的网站就像你的用户的浏览器没有javascript,然后一旦所有功能都工作,添加ajax来改善用户体验。但是自从ajax的早期开始,Google肯定会推动这一局面,并且很多人希望在他们的网站上使用ajax创建这些惊人的丰富用户体验。我和很多人一起工作过,他们非常喜欢在ajax中实现很多功能,但很少有人能够实现这些功能。我当然没有自己的排骨,并且对于看起来非常酷的错误测试功能非常沮丧......如果你以某种方式使用它们......交叉你的手指。其中很多都与测试有关,单元测试是一回事,在浏览器测试中是另一回事,而且我经常发现自己非常努力只是为了让单元测试到位,更不用说整个浏览器测试套件了。

You have to decide what you want your user experience to be like, how ajax fits into those decision and then chose when to implement the ajax. Early for sites with major features implemented in ajax only, later for sites where ajax just addes UX sugar. That is my $0.02, I'm sure there is someone with the opposite opinion.

您必须决定您希望您的用户体验如何,ajax如何适应这些决定,然后选择何时实施ajax。对于仅在ajax中实现主要功能的网站而言,之前的早期版本仅适用于ajax仅添加UX糖的网站。这是我的0.02美元,我敢肯定有人有相反的意见。