today_ai_weather/app/javascript/controllers/page_load_time_controller.js
songtianlun b01cbe960a fix: round load time to the nearest whole number
- Update load time display to show the rounded value instead of the
  raw measurement.
- This change improves the readability of the load time for end users
  by providing a more user-friendly format.

The adjustment enhances the user experience by presenting the load time
in a cleaner and more comprehensible manner.
2025-02-14 11:09:33 +08:00

18 lines
528 B
JavaScript

import {Controller} from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["timer"]
connect() {
// 记录页面加载开始的时间
const startTime = performance.now();
// 监听页面加载完成事件
window.addEventListener('load', () => {
const endTime = performance.now();
const loadTime = endTime - startTime;
// 更新显示
this.timerTarget.textContent = Math.ceil( loadTime );
});
}
}