Currently, I am working on a small project which requires me to calculate the time taken for each page to load. To achieve this, I am utilizing the Performance API. Specifically, I am using the getEntriesByName() method within the Performance API as demonstrated below:
performance.getEntriesByName(window.location.href)
To view the results, simply open your console by pressing F12 on your keyboard and run the above line of code.
RESULT
connectEnd: 1.55999994603917
connectStart: 1.55999994603917
decodedBodySize: 132839
domComplete: 1405.1149999722838
domContentLoadedEventEnd: 887.4099999666214
domContentLoadedEventStart: 867.9899999988265
name: "https://stackoverflow.com/questions/ask"
nextHopProtocol: "h2"
redirectCount: 0
....
The data displayed pertains to the specific page being loaded. The name value indicates the URL of the page. Running the above code on various pages will provide metrics for each individual page.
ISSUE
An issue arises when running this code on different pages within a Vue.js project. Instead of returning metrics for the particular page, it only retrieves information for the main page. For example, if the main page is /dashboard, running the code on /dashboard/users results in an EMPTY array.
NOTE
If anyone can determine why this occurs or suggest an alternative method to obtain the RESULT values without using the JavaScript performance API, please share your insights. It would be valuable to understand how to access these details without relying on the performance API or suggestions for resolving this discrepancy.
CHECK THIS
Explore a website developed in Vue.js where you can change routes and replicate the procedure mentioned above. This issue seems to persist across all Vue.js websites. Any insights into why this is a prevalent issue with Vue.js websites would be appreciated.