足踝外科主要看什么| 51岁属什么| 乜是什么意思| 丹宁蓝是什么颜色| 高考成绩什么时间公布| 师夷长技以制夷是什么意思| 深海鱼油的作用是什么| 毛戈平化妆品什么档次| 天秤女喜欢什么样的男生| 九死一生什么意思| 小孩便秘吃什么通便快| 什么是善| 月经来了一点就没了是什么原因| 裤裙配什么上衣好看| 1981属什么生肖| 身上起红斑是什么原因| 肝硬化有什么症状| 劲仔小鱼是什么鱼做的| 铁蛋白低是什么原因| 什么病人要补氯化钾呢| 三峡大坝什么时候建成的| 扒拉是什么意思| 洋参片泡水喝有什么功效| 贼眉鼠眼是什么生肖| 男士检查精子挂什么科| 湿气重有什么表现| unny是什么牌子| 幻灭是什么意思| 逃之夭夭是什么意思| 查传染病四项挂什么科| 什么是虚拟币| 灵芝有什么功效| 小儿外科主要看什么病| 增强免疫力吃什么维生素| 6月21号是什么日子| 吃什么水果降血压| category是什么意思| 2002年出生属什么| 嘴角烂了擦什么药| 玄是什么颜色| blacklabel是什么牌子| fashion是什么意思| 麦粒肿滴什么眼药水| 离歌是什么意思| 什么情况需要做肠镜| 醋有什么功效和作用| t细胞是什么| 金字旁的字与什么有关| 做梦梦见搬家是什么意思| 梦见男朋友出轨了是什么意思| 马蜂菜什么人不能吃| 自汗吃什么中成药| 为什么一喝阿胶睡眠就好了| 菜场附近开什么店好| px是什么单位| 观落阴是什么意思| 月经推迟不来吃什么药| 静脉曲张是什么原因| 主页是什么意思| 什么东西解酒| 荨麻疹不能吃什么食物| 孕妇吃什么蔬菜好| 什么狗不咬人| 喉咙有异物感挂什么科| 生死离别代表什么生肖| 不着相是什么意思| 疑心病是什么意思| 63年属什么生肖| 四川人喜欢吃什么| 化疗病人吃什么好| 桃花什么时候开放| 笨和蠢有什么区别| 农历6月21日是什么星座| 女生是t是什么意思| 冬天种什么蔬菜合适| 咖啡伴侣是什么| 垂死病中惊坐起什么意思| 丑角是什么意思| 子宫内膜炎用什么药效果好| 考试穿什么颜色的衣服| 月经每个月都提前是什么原因| 韩红和张一山什么关系| 腹部b超可以检查什么| look是什么意思| 离子检测是检查什么| 拉垮什么意思| 部级干部是什么级别| 夜莺是什么鸟| 飞机什么时候开始登机| 身陷囹圄是什么意思| 五花肉和什么菜炒好吃| gg是什么牌子| bacardi是什么酒| 心脏不好吃什么水果好| 胃溃疡能吃什么水果| 甲亢吃什么好的更快| 什么药能治口臭| 总胆红素偏高什么意思| 吃什么水果能壮阳| lp是什么的简称| 氯偏高是什么原因| 阿司匹林不能和什么药一起吃| 什么都想吃| 假借是什么意思| 早上四五点是什么时辰| maga是什么意思| 手机root后有什么好处和坏处| sun代表什么| 占有欲强什么意思| 座山雕什么意思| 什么东西最伤肾| 来月经喝红糖水有什么好处| 为什么没有西京| 大便发绿色是什么原因| 梦见自己抬棺材是什么意思| 蜘蛛痣长什么样| np是什么意思| 鸡蛋黄发红是什么原因| 酚妥拉明是什么药| 舌苔白厚吃什么药见效快| 孕妇血糖高可以吃什么水果| hcg偏高是什么原因| 燕然未勒归无计的上一句是什么| 烂仔是什么意思| 起伏不定是什么意思| 铁是什么颜色| 天天想睡觉没精神是什么原因| 不想吃饭没胃口是什么原因| 拍花子是什么意思| 梦见打群架是什么意思| 牙疼可以吃什么| 冠带什么意思| 口腔异味吃什么药| 尿路感染吃什么药比较好的快| 抗核抗体弱阳性说明什么| 先兆临产是什么意思| 为什么一进去就想射| 吃汤圆是什么节日| 二级乙等医院什么档次| 线差是什么意思| 多面手是什么意思| 让平是什么意思| 烫伤擦什么药| 溜冰是什么意思| 哈尔滨有什么好吃的| 什么是房补| 乳房疼挂什么科室| 什么是备皮| 什么是肌无力| 美国人的祖先是什么人| 日龙包什么意思| 孙子兵法到底说什么| 脑萎缩是什么原因| 11月2日什么星座| 梦见自己吐血是什么征兆| 老匹夫是什么意思| 黑裤子配什么颜色的鞋| 杜比全景声是什么意思| 骨骼肌率是什么意思| 顺铂是什么药| 风采是什么意思| 什么原因导致卵巢早衰| 2月出生是什么星座| .什么意思| 头发细软是什么原因| 梦见木头是什么意思| 血虚吃什么好| 母亲属虎孩子属什么好| 说梦话是什么原因| 吃樱桃有什么好处| 眼睛模糊吃什么好| 小孩子手脚脱皮是什么原因| 计算机二级什么时候考| 什么的虫子| 孩子睡觉咬牙齿是什么原因引起的| 胆囊腺肌症是什么病| 吃什么药可以延长射精| 老是掉头发什么原因| 甘油三脂高是什么意思| qrs是什么意思| 头部mra是什么检查| 懋是什么意思| 仙人掌能治什么病| 三冬是什么意思| 什么茶助眠| 朝阳是什么意思| 第一磨牙什么时候换| 射精无力吃什么药最佳| 半夏是什么意思| prr是什么意思| 耳朵一直痒是什么原因| dido是什么牌子| 嗜是什么意思| 什么的蹦跳| 什么清肠茶好| 什么的海底| 短发女人吸引什么男人| 幽门螺旋杆菌吃什么药最好| 心肌缺血有什么症状| 心衰竭是什么症状| 山代表什么动物| 轻断食是什么意思| 荷里活什么意思| 长期喝蜂蜜水有什么好处| 膀胱过度活动症是什么原因引起的| 阴道有灼热感是什么原因| 列文虎克发明了什么| 失心疯是什么意思| 吃什么长内膜最快最有效| 睡觉多梦是什么原因| 脾虚湿气重吃什么中成药| 拔罐对身体有什么好处和坏处| 冰冻三尺的下一句是什么| vol是什么意思| 七星瓢虫吃什么食物| 老头乐是什么| 日本旅游买什么东西最划算| 孺子是什么意思| 外来猫进家有什么预兆| 巨峰葡萄为什么叫巨峰| 坐骨神经痛吃什么药快| 12月27号是什么星座| 眼疲劳用什么眼药水| 左肩膀疼痛是什么原因| 万事如意是什么生肖| 妈妈的妹妹应该叫什么| 4月14日是什么星座| 闲鱼转卖什么意思| 丰胸吃什么食物有效果| 什么牌子的益生菌调理肠胃比较好| 愿力是什么意思| 肚子经常胀气是什么原因| 考试为什么要用2b铅笔| 冰粉的原材料是什么| 乳腺增生1类什么意思| 热泪盈眶的盈是什么意思| 手指脱皮是什么原因造成的| 婊是什么意思| 陕西为什么叫三秦大地| 咖啡加奶有什么坏处和好处| 什么肉不含嘌呤| 叶酸是什么维生素| 为什么耳屎是湿的| 520和521的区别是什么| 胸口闷堵是什么原因| 乳房头疼是什么原因| 四川有什么好吃的| 六月十九是什么星座| 男士吃什么壮阳最厉害| 苹果和什么榨汁减肥| 回复1是什么意思| g6pd是什么意思| 触霉头是什么意思| 纸是什么生肖| 拔苗助长是什么生肖| 手抖是什么情况| 三月初六是什么星座| 孩子吃什么能长高| 6424什么意思| 顺风耳是什么意思| 脑白质是什么| 菊花代表什么象征意义| 肺部做什么检查最准确| 玫瑰疹是什么病| 百度
丢钱是什么预兆 舌头发麻是什么原因 乙状结肠冗长是什么意思 拉k是什么意思 羊鞭是什么部位
最多笔画的汉字是什么 海马萎缩是什么情况 胸闷气短吃什么药疗效比较好 女人喜欢什么礼物 sin是什么边比什么边
四维和大排畸有什么区别 可遇不可求什么意思 为什么睡觉会张嘴 弱肉强食是什么意思 凌晨五点是什么时辰
cg是什么意思 林丹用的什么球拍 爬坡是什么意思 什么是情感障碍 utc是什么时间
电磁炉用什么锅最好hcv7jop5ns5r.cn 腰痛宁为什么晚上吃hcv9jop6ns7r.cn 虾仁和什么炒好吃mmeoe.com 熊吃什么0297y7.com 女性胃炎有什么症状hcv8jop3ns9r.cn
三分三是什么药hcv7jop5ns4r.cn 贫血喝什么口服液hcv8jop8ns5r.cn 伤寒现在叫什么病hcv8jop6ns7r.cn 身上出现白块什么原因hcv7jop6ns2r.cn 鸟屎掉手上有什么预兆hcv8jop8ns1r.cn
淋巴结肿大是什么样子的hcv7jop9ns6r.cn 寒湿体质吃什么中成药hcv8jop0ns1r.cn 膝关节积液吃什么药hcv8jop2ns6r.cn 胃出血吃什么药好hcv9jop4ns9r.cn 天干是什么意思wzqsfys.com
柳絮是什么hcv8jop9ns4r.cn 什么地散步hcv7jop5ns3r.cn 玮是什么意思hcv8jop6ns4r.cn 尿液浑浊是什么原因hcv7jop6ns7r.cn 吴五行属什么hcv9jop6ns3r.cn
The Monitor

李晨秦岚演绎经典爱情 《红海行动》唯一女战士蒋璐霞首曝拍摄幕后故事

百度 王健表示,联谊会将团结引领我省广大党外知识分子发挥自身的聪明才智,为新福建建设献计出力。

10 minute read

Published

Share

Best practices for modern frontend monitoring
Mary Jac Heuman

Mary Jac Heuman

Single-page applications (SPAs) provide some significant benefits over multiple-page apps. For JavaScript developers using frameworks like React or Vue, they offer flexibility in moving application logic to the frontend, reducing the need for complex backend operations. For users, SPAs can provide a smooth experience with a highly interactive UI and fewer page loads. But, with increased sophistication, there are some tradeoffs. For example, users could be accessing your site on older or less powerful devices than your developers can test on, which may mean that the additional complexity is the user's burden. Developers of SPAs need to monitor end-user experiences in order to ensure their sites run smoothly on all devices.

However, frontend monitoring concepts and tools are still evolving to keep up with JavaScript and SPA frameworks. Traditional methods of monitoring frontend performance are based on measuring the timing of completed page loads. In the case of SPAs, which only have a single page, this method only accounts for the first few seconds of the user experience. As the user navigates an SPA, it will re-render page components to reflect the new data state instead of loading a new document. In order to accurately monitor the performance of your application, you need to be able to track dynamic page elements like animations, API calls, and rendering lifecycles that can interrupt user experience if there are slowdowns.

When it comes to frontend monitoring, we recommend a user-centric approach by listening to browser events and tracking user interactions over time. Google and the W3C Web Performance Working Group have worked on defining new APIs that take observation of user interactions as the basis of site performance. With these APIs, you can build visibility into your app by breaking down interactive elements and timing user actions as finely as possible

In this post, we’ll specifically look at how to measure three aspects of single-page apps that can help you optimize your users' experience:

Route changes

Fluid transitions between different parts of a web application are crucial for good end-user experience. Let's say you maintain an e-commerce single-page application that contains a promotional landing page. On the landing page is a large hero image advertising a product. Users can visit this page either via a direct link, or by clicking through the main site. In order to ensure smooth page transitions, you decide the hero image should load in two seconds or less. Beyond that, users could become frustrated and leave the site.

One common way to measure site transitions is by tracking the Largest Contentful Paint (LCP). This estimates when a page has finished loading based on how long it took for the largest <img>, <video>, or <svg> element to become visible. But, because SPAs modify the browser route and re-render the site components, the largest element on the previous page might not reload on the new one. So, measuring loading times requires a way to detect changes in the browser that don’t depend on standard loading events. The illustration below shows the sequence of browser loading events on a traditional website versus an SPA:

Traditional website vs SPA page loads on route changes
Traditional website vs SPA page loads on route changes

In this case, instead of page load events, we recommend listening to route changes and using those to calculate performance metrics.

Listen to route changes

In order to track route changes, you need to instrument your code to watch for different browser events than a full page load. The User Timing API provides functions that make it easy to define your own loading indicators so that you can precisely measure page and resource load times.

First, using the browser History API, listen for the popstate event, which is fired when the browser route changes. (Be careful to take into consideration instances where it might not indicate a whole new page.Then, use the User Timing API to set a window.performance.mark() to indicate the route change has begun.

route-change-mark.js
window.onpopstate = function(e) {
window.performance.mark('route_change_start');
}
...after requests finish and components render
window.performance.measure('route_change','route_change_start')

Once the component of the new view that you select as your indicator of readiness has been rendered (in this case, the hero image has appeared), you can pass the mark to the window.performance.measure function, which creates a finish mark and calculates the difference between the two. This makes it easy to log the loading time of your application's route changes, which you can then forward to a logging service, such as Datadog.

When timing each route change event, it’s helpful to also track the loading time of individual resources to see where slowdowns are occuring. Below is a waterfall visualization of a route change that shows how long it takes to load some web fonts and JSON files. We can see that the overall view took 2.26 seconds to fully load, and iIt’s easy to see exactly which files are slowing down the site and which one encountered an error while loading.

Waterfall visualization of loading resources on view change
Waterfall visualization of loading resources on view change

Automate to save time

Manually tracking route changes can become cumbersome if you’re adding markers for each page transition. Another way to time page transitions is to create a loop that triggers after a route change has been detected. For example, after creating the initial performance marker, you can instrument your application to check every 100ms to see if there have been any network requests or DOM mutations. If any are initiated or completed during that time, your application will wait another 100ms. Otherwise, it takes the previous 100ms mark as your loading time. Datadog uses a similar method to track page loads for SPA route changes.

User interactions

Tracking the duration of key user interactions across your application can reveal slowdowns. To optimize user flow, it’s important to collect as much fine-grained information as possible.

Using the same e-commerce site example, when a user adds an item to their cart, the action triggers a modal popup with some suggested products. This is a key interaction to monitor because it triggers a lot of activity in the browser, including a series of API calls, updating the data state, and then re-rendering the components. Latency during any of these tasks can quickly add up, especially if the user is running the site on an older mobile device or computer. If the popup takes too long to load or respond to input the user will feel blocked from their goal (buying something), and the site potentially loses a customer.

As with route changes, you can add event listeners to key UI elements, such as button clicks, scrolls, and key presses, which trigger state changes. This allows you to easily track load times for important user interactions and find ones that take the longest. Again, 100ms has been proven to be the threshold above which users lose the feeling that interactions are natural and fluid.

Importance of end-to-end monitoring

Key user interactions within an SPA, including our modal flow, often depend on multiple behind-the-scenes jobs, such as API calls, data state changes, and component re-rendering. This means that monitoring the performance of these backend processes is crucial when determining the cause of any latency in the frontend. For instance, slowdowns in your suggested product modal may be the result of an API timeout, which wouldn't necessarily be revealed by monitoring only the loading time of the modal itself. Having visibility into different layers of your stack can help you pinpoint where code or database issues are causing slowdowns on the frontend.

For example, below we see a flame graph of a request initiated from the frontend (to fetch /products.json). We can see a breakdown of all of the network requests and backend tasks this request triggered. Each span appears with its duration and detailed context from the execution, including any errors that may have occurred. With a clear timeline and hierarchy of API actions, you can tell right away the problem was a NoMethodError originating in the controller. Without this visibility into how requests propagate across our stack, it is much more difficult to isolate where the causes are of any latency in the user experience.

Correlating frontend actions with backend traces
Correlating frontend actions with backend traces

Watching for Long Tasks on the frontend can also help surface slowdowns impacting user experience and scripts requiring optimization. A Long Task is defined as a section of JavaScript code blocking the main UI thread for at least 50ms. You can catch these either on the code level, or in your browser profiler for quick visualization and debugging.

Error tracking

Since SPAs run more complex code on the user’s device, you won’t find their browser errors unless you instrument your code to log them. If you don't, you may only find out about errors when support tickets come in or revenue drops. Catching and logging application errors will help you spot issues before this happens. For example, if the “checkout” button on your e-commerce site is unable to connect to the backend API, it would cause an error in the browser. When a user clicks the button and nothing happens for them, they might become frustrated and leave the site. Without tracking user browser errors, you would’ve only been alerted to the problem from a rise in the number of abandoned carts.

You can do this by using a GlobalEventHandler like window.onError to catch and log error events. When logging errors, you should collect as much information as possible about the user’s browser, OS, application version, etc. This provides more context around the problem's impact and possible cause when you're debugging.

In order for error tracking to be effective, you need to be able to separate signal from noise. For example, third-party libraries, browser extensions, and other dependencies may generate errors unrelated to your site’s performance. It can be challenging to filter through them for actionable information. Using a third-party monitoring solution to aggregate similar error logs can help you analyze them and surface critical issues. Below is an example Datadog's Error Tracking, which enables you to more easily triage errors from across your stack.

Logging and aggregating console errors in Datadog
Logging and aggregating console errors in Datadog

Tackle errors before they happen

Creating and maintaining an end-to-end testing workflow to test your application in real-world conditions can help you detect browser errors before they affect your users. Synthetic monitoring works by simulating API requests and site interactions to test complex user journeys, like adding items to a cart or signing up for a service.

Third-party tools like Datadog Synthetic Monitoring allow you to automate test creation and execution, so you can simulate site behavior under a variety of conditions, like a user’s geographic location or the type of device they’re using. This way, you can integrate frontend behavior testing as part of your CI workflow and catch faulty code before it interrupts the user experience.

Start monitoring your SPAs

As frontend frameworks and SPAs continue to grow in complexity, it can be difficult to measure performance when the bulk of the rendering is done on the user’s device. That’s why we recommend thinking of frontend monitoring in terms of tracking the user journey. By timing user interactions and resource loading, as well as staying on top of in-browser errors, you can create visibility and collect actionable insights to optimize your single-page application.

A monitoring solution like Datadog can help you get deep visibility into the frontend performance of your applications along with the rest of your stack. Datadog Real User Monitoring (RUM) automatically tracks latency for user actions and collects key metadata such as the user's browser, OS, and device, as well as their geolocation. Datadog Synthetic Monitoring enables you to create browser tests that simulate real-world conditions to test key user journeys within your frontend application. Error Tracking collects and aggregates JavaScript errors for alerting and troubleshooting. And, together with Datadog APM, you can correlate frontend and backend performance of requests as they propagate across your stack, all in a single pane of glass.

Get started monitoring your SPAs today with Datadog today. If you’re not signed up with Datadog yet, you can start your .

Related Articles

How we use our Digital Experience Monitoring products to reduce friction in frontend testing and debugging

How we use our Digital Experience Monitoring products to reduce friction in frontend testing and debugging

Monitor Core Web Vitals with Datadog RUM and Synthetic Monitoring

Monitor Core Web Vitals with Datadog RUM and Synthetic Monitoring

Easily test and monitor your mobile applications with Datadog Mobile Application Testing

Easily test and monitor your mobile applications with Datadog Mobile Application Testing

Best practices for monitoring static web applications

Best practices for monitoring static web applications

Start monitoring your metrics in minutes

百度