最佳实践:如何处理浏览器和网站导航的并发性

时间:2023-01-31 03:28:53

It is a well known problem to every web developer. As far as I tried to find a good solution to this problem - there was none (or at least I could not find it).

这是每个Web开发人员都熟知的问题。至于我试图找到这个问题的一个很好的解决方案 - 没有(或至少我找不到它)。

Lets assume the following:

The user does not behave, as he was expected to. The actual project I'm working in uses a navigation within the web portal. But if the user uses the browser's back button, the whole thing becomes jeoprady[?] and the result was not always predictable.

用户没有像预期的那样表现。我正在使用的实际项目使用Web门户中的导航。但是如果用户使用浏览器的后退按钮,则整个事情变成了jeoprady [?],并且结果并不总是可预测的。

We used the struts framework and stored the back-url into forms - at some places, where we needed a back-url - this has been rendered out of this form's back-url. For there was only a singe field for this information and therefore it was not possible of going back multiple steps.

我们使用了struts框架并将back-url存储到表单中 - 在某些地方,我们需要一个back-url - 这已经从这个表单的back-url中呈现出来了。因为这个信息只有一个单一的字段,因此无法返回多个步骤。

When you change the "struts-flow" - which may result in using a different form - this information will be lost.

当您更改“struts-flow”(可能导致使用其他表单)时,此信息将丢失。

If the user dares to put a bookmark somewhere within your webapp - this information may never have been set and again the result will again be either unpredictable or not flexible enough!

如果用户敢于在您的webapp中放置一个书签 - 这些信息可能永远不会被设置,并且结果将再次变得不可预测或不够灵活!

My "solution":

I was storing every navigation-relevant page the user visited onto a stack-like storage into the session. This means a navigation-path is collected and stored for later navigations.

我将用户访问过的每个与导航相关的页面存储到会话中的堆栈式存储中。这意味着收集并存储导航路径以供以后导航。

At any page within the webapp, where back-navigations are involved I used a self-made tag which renders the stack-content into the url.

在webapp中涉及反向导航的任何页面,我使用了一个自制的标签,它将堆栈内容呈现到网址中。

And thats it. When this back-url was clicked, the stack has been filled with the content from the back-url clicked by the user (which holds all information from the stack once the back-link was rendered).

就是这样。单击此反向URL时,堆栈已填充了用户单击的后备用户内容(一旦呈现后向链接,该内容将保留堆栈中的所有信息)。

This is quite clear, because a click on a link is a clear state, where the web developer exactly knows, where the user "is" a this very moment - absolutely independant from whatever the user did before (e.g. hitting the browser back button multiple times). Then the navigation stack is built upon this new state.

这很清楚,因为链接上的点击是一个清晰的状态,Web开发人员确切地知道,用户“是”这个时刻 - 与用户之前所做的完全无关(例如,点击浏览器后退多个按钮)次)。然后导航堆栈建立在这个新状态之上。

Resumé: It becomes clear, that this won't be the best solution. But it allows storing additional information on the stack like page parameters and some other useful stuff (further developments possible).

简历:很明显,这不是最好的解决方案。但它允许在堆栈上存储附加信息,如页面参数和其他一些有用的东西(可能的进一步发展)。

So, what were your solutions to this problem?

那么,你对这个问题的解决方案是什么?

cheers,

mana

1 个解决方案

#1


1  

The stack solution sounds interesting, but it will probably break if the user chooses to navigate "in parallel" on different tabs or using bookmarks.

堆栈解决方案听起来很有趣,但如果用户选择在不同选项卡上“并行”导航或使用书签,它可能会中断。

I'm afraid I don't really understand why you have to keep all this state for each user: ideally the web should follow the REST principle and be completely stateless. Therefore a single URL should identify a single resource, without having to keep the navigation history of each user.

我担心我不明白为什么你必须为每个用户保持所有这种状态:理想情况下,网络应该遵循REST原则并且完全无状态。因此,单个URL应标识单个资源,而不必保留每个用户的导航历史记录。

If your web app relies heavily on AJAX, you could try to implement something like GMail (admittedly, not so easy...), where each change in the interface is reflected in a change in the page URL. Therefore each page is identified by the current URL and the user can navigate concurrently or use the back button as usual.

如果你的网络应用程序在很大程度上依赖于AJAX,你可以尝试实现像GMail这样的东西(诚然,不那么容易......),其中界面中的每个变化都反映在页面URL的变化中。因此,每个页面都由当前URL标识,用户可以同时导航或像往常一样使用后退按钮。

#1


1  

The stack solution sounds interesting, but it will probably break if the user chooses to navigate "in parallel" on different tabs or using bookmarks.

堆栈解决方案听起来很有趣,但如果用户选择在不同选项卡上“并行”导航或使用书签,它可能会中断。

I'm afraid I don't really understand why you have to keep all this state for each user: ideally the web should follow the REST principle and be completely stateless. Therefore a single URL should identify a single resource, without having to keep the navigation history of each user.

我担心我不明白为什么你必须为每个用户保持所有这种状态:理想情况下,网络应该遵循REST原则并且完全无状态。因此,单个URL应标识单个资源,而不必保留每个用户的导航历史记录。

If your web app relies heavily on AJAX, you could try to implement something like GMail (admittedly, not so easy...), where each change in the interface is reflected in a change in the page URL. Therefore each page is identified by the current URL and the user can navigate concurrently or use the back button as usual.

如果你的网络应用程序在很大程度上依赖于AJAX,你可以尝试实现像GMail这样的东西(诚然,不那么容易......),其中界面中的每个变化都反映在页面URL的变化中。因此,每个页面都由当前URL标识,用户可以同时导航或像往常一样使用后退按钮。