有關單頁應用程式的體驗問題
---恢復內容開始---
##What is a single-page application
The so-called single-page application refers to the integration of multiple functions on one page, or even the entire system has only one page (one html), and all business functions are its Submodules are connected to the main interface in a specific way.
##Why there are single-page applications
We know that part of the reason for the emergence of ajax technology is to allow users who visit the web page to view data changes on the page without refreshing the page. We can say that ajax improves the experience.
With the development of the Internet, the services carried by the browser have become more and more complex. The web front-end is no longer a simple page, a gadget that can be partially refreshed with Ajax. Applications with dozens of sub-pages can be found everywhere on the market. These subpages share many shared resources (static and dynamic), and it takes a lot of time to load them. If you want to avoid loading these resources repeatedly, there is an obvious way - put them into one HTML.
So it is a further sublimation of ajax technology, taking the refresh-free mechanism of ajax to the extreme, so it can create a smooth user experience comparable to desktop programs.
##Troubles caused by single-page applications
We know that putting a dozen or twenty sub-page programs in an HTML cannot be done by cut+paste. The result of putting together originally unrelated programs is the mass-energy equation of the program world. Errors = (More Code)^2
##The experience of single-page applications
Getting back to the subject, how to enhance the single-page application as much as possible What is the operating experience of page application?
Then let’s first take a look at what affects the experience for users
1. The initial loading speed of the page
2. The interactive response
3. The correctness of page data (especially under abnormal network conditions)
--
In fact, many articles have talked about the first two points more. Here I will try my best to briefly mention them and focus on the third point.
#Initial page loading speed
-On-demand loading of static resources (under the premise of good modularization, use module bundler tools such as webpack and systemjs)
-On-demand loading of dynamic resources Need to obtain (needs a good architecture of the front-end data layer)
- Server-side rendering (during the page loading process, the front-end "obtains" data and "generates" the page, completes it on the server side. Not applicable to the first screen Overly complex applications)
#Interactive response
- Speed: data returned from the backend request, front-end cache, and subsequent synchronization. Avoid repeated requests for the same data.
- Exception handling: Nowadays, mobile office is popular. How to give users a good wait or prompt on the UI when the network condition is not good, we should not underestimate the correctness of the page data
This is what I want to talk about. We have encountered many problems in practice and have tried some solutions.
I personally feel that if you want to do this well, just these words are needed: **"Good cache management"**, the cache here refers to the front-end cache model.
Don’t look at just these few words, it’s quite difficult to do. Why?
# Let’s talk about the sources of memory first, there are the following types:
- Browser cache (indexDB, localStorage and the like)
- http request
- webSocket push
Different sources affect the same data, which requires good abstraction to allow the business layer to shield the perception of the data source. Existing widely used libraries to solve this problem include RxJs, CycleJS, etc., and there were also some earlier People came up with the concept of MVI because of this.
#Let’s talk about memory changes
There is no need to go into details about changes in normal states. Here we only talk about a few types of abnormal states.
##http request failed
There is a word that needs to be mentioned here, called **"operation compensation"**
What is operation compensation?
Logically speaking, when we operate on the interface and create a task, the new task should not be displayed immediately, but should wait until the server confirms success before adding it to the interface. . But it is very likely that our network is not good and users will have to wait a long time for this step. From the perspective of user experience, this is not good, so we can put the interface up first, and then backfill some unique identifiers and other things into the memory data after the message of successful creation comes back. ######Single-step operation compensation is not too difficult. If there are multiple steps, it will be very troublesome. For example, in an extreme case, the user adds a new task and the server has not returned yet. , he immediately creates a subtask under this task, but the subtask does not have the ID of the parent task at this time. If you want to compensate for this step, it will be more troublesome. It is even said that after performing several consecutive operations, it is found that the previous operation failed, and the subsequent processing will be very complicated. ######Our products also encounter this problem. Our approach is - **"compromise"**, for important data, make single-step compensation or two-step compensation. If the dependency relationship of the front-end model is complex and the write operation of the superior model fails, or there are too many steps of compensation, the user will be notified in advance and the user's interaction entrance will be locked on the UI to avoid subsequent write operations. ######If you continue to do it here, you can still do it. The idea is similar to the offline application. The results of the operation are recorded locally on the client. Wait until the network is normal, and then synchronize the data with the background.
##Disconnection and reconnection
Network jitter, network switching, computer hibernation and restarting, etc., lead to us needing to face more complex network conditions, then When the user connects to the Internet again, the application needs to reconnect.
At this time, an ideal single-page application will synchronize back the final results of all previous events, that is, the latest status, when reconnecting.
Our application has collaborative business. Users in the same enterprise share the same model and synchronize it through webSocket to ensure the immediacy and correctness of the model. So this is also a big challenge for us. Our solution is to resend webSocket.
##Hot update
As mentioned earlier, users may have our application open for a long time and then not refresh it in the middle. Under normal circumstances, all business changes should be pushed over, and the status fed back by the interface is always the latest and in line with the current situation. But we need to consider another issue, what about system upgrades?
Of course we can push a notification: This system has been upgraded, please click refresh. But can it be done better? This is possible. To achieve this goal, we must use hot update to maximize the modularization and change management of the code. Each updated code module is also pushed over and applied as a patch to the current on the system. This mechanism requires high standards of the development team.
##Finally
I once heard a saying, how to judge the technical level of a single-page product?
It can be used continuously for several days without being closed, and there is no need to refresh the page. The application can still be used normally, correctly and smoothly.
I believe students who have done single-page applications will understand the meaning of this.
以上是有關單頁應用程式的體驗問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

推薦適合地理資訊科學專業學生用的電腦1.推薦2.地理資訊科學專業學生需要處理大量的地理資料和進行複雜的地理資訊分析,因此需要一台性能較強的電腦。一台配置高的電腦可以提供更快的處理速度和更大的儲存空間,並且能夠更好地滿足專業需求。 3.建議選擇一台配備高效能處理器和大容量記憶體的電腦,這樣可以提高資料處理和分析的效率。此外,選擇一台具備較大儲存空間和高解析度顯示器的電腦也能更好地展示地理資料和結果。另外,考慮到地理資訊科學專業學生可能需要進行地理資訊系統(GIS)軟體的開發和編程,選擇一台支援較好的圖形處

聚類演算法中的聚類效果評估問題,需要具體程式碼範例聚類是一種無監督學習方法,透過對資料進行聚類,將相似的樣本歸為一類。在聚類演算法中,如何評估聚類的效果是一個重要的問題。本文將介紹幾種常用的聚類效果評估指標,並給出對應的程式碼範例。一、聚類效果評估指標輪廓係數(SilhouetteCoefficient)輪廓係數是透過計算樣本的緊密度和與其他簇的分離度來評估聚類效

極致反編譯體驗:推薦五款最受歡迎的Java反編譯工具導語:隨著科技的發展,軟體的安全性與智慧財產權保護越來越重要,而反編譯技術正是重要的手段。本文將介紹五款目前最受歡迎的Java反編譯工具,讓你體驗到極致的反編譯體驗。一、JD-GUIJD-GUI是一款開源的Java反編譯工具,其特點是操作簡單、介面友善。透過JD-GUI,你可以將Java的class檔案反

iPhone以其強大的性能和多方面的功能而聞名,它不能倖免於偶爾的打嗝或技術困難,這是複雜電子設備的共同特徵。遇到iPhone問題可能會讓人感到沮喪,但通常不需要警報。在這份綜合指南中,我們旨在揭開與iPhone使用相關的一些最常遇到的挑戰的神秘面紗。我們的逐步方法旨在幫助您解決這些常見問題,提供實用的解決方案和故障排除技巧,讓您的裝置恢復到最佳工作狀態。無論您是面對一個小故障還是更複雜的問題,本文都可以幫助您有效地解決這些問題。一般故障排除提示在深入研究具體的故障排除步驟之前,以下是一些有助於

解決jQuery.val()無法使用的問題,需要具體程式碼範例對於前端開發者,使用jQuery是常見的操作之一。其中,使用.val()方法來取得或設定表單元素的值是非常常見的操作。然而,在一些特定的情況下,可能會出現無法使用.val()方法的問題。本文將介紹一些常見的情況以及解決方案,並提供具體的程式碼範例。問題描述在使用jQuery開發前端頁面時,有時候會碰

弱監督學習中的標籤獲取問題,需要具體程式碼範例引言:弱監督學習是一種利用弱標籤進行訓練的機器學習方法。與傳統的監督學習不同,弱監督學習只需利用較少的標籤來訓練模型,而不是每個樣本都需要有準確的標籤。然而,在弱監督學習中,如何從弱標籤中準確地獲取有用的信息是一個關鍵問題。本文將介紹弱監督學習中的標籤獲取問題,並給出具體的程式碼範例。弱監督學習中的標籤獲取問題簡介:

機器學習模型的泛化能力問題,需要具體程式碼範例隨著機器學習的發展和應用越來越廣泛,人們越來越關注機器學習模型的泛化能力問題。泛化能力指的是機器學習模型對未標記資料的預測能力,也可以理解為模型在真實世界中的適應能力。一個好的機器學習模型應該具有較高的泛化能力,能夠對新的數據做出準確的預測。然而,在實際應用中,我們經常會遇到模型在訓練集上表現良好,但在測試集或真實

如龍8酒類大師考試所涉及的問題包括哪些?對應的答案是什麼?如何快速通過考試?酒類大師考試活動有許多需要回答的問題,我們可以參考答案來解決。這些問題都牽涉到酒的知識。如果需要參考,讓我們一起來看看如龍8酒類大師考試問題答案的詳細解析!如龍8酒類大師考試問題答案詳解1、關於「酒」的問題。這是一種管由王室建立的蒸餾灑廠生產的蒸餾酒,以夏威夷大量種植的甘盤的糖分為原料釀製。請問這種酒叫什麼?答:蘭姆酒2、關於「酒」的問題。圖片上是一種使用乾琴灑和乾苦艾酒調配而成的酒。它的特點是加入了橄欖,被譽為「雞尼酒
