-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
50 lines (37 loc) · 1.51 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
title: "PerformanceElementTiming: loadTime property"
short-title: loadTime
slug: Web/API/PerformanceElementTiming/loadTime
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.PerformanceElementTiming.loadTime
---
{{APIRef("Performance API")}}{{SeeCompatTable}}
The **`loadTime`** read-only property of the {{domxref("PerformanceElementTiming")}} interface always returns `0` for text. For images it returns the time which is the latest between the time the image resource is loaded and the time it is attached to the element.
## Value
A {{domxref("DOMHighResTimeStamp")}} with the `loadTime` of the element. Always `0` for text.
## Examples
### Logging `loadTime`
In this example an {{HTMLElement("img")}} element is being observed by adding the [`elementtiming`](/en-US/docs/Web/HTML/Attributes/elementtiming) attribute. A {{domxref("PerformanceObserver")}} is registered to get all performance entries of type `"element"`. The `buffered` flag is used to access data from before the observer was created. Calling `entry.loadTime` returns the loadTime of the image element.
```html
<img
src="image.jpg"
alt="a nice image"
elementtiming="big-image"
id="myImage" />
```
```js
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.identifier === "big-image") {
console.log(entry.loadTime);
}
});
});
observer.observe({ type: "element", buffered: true });
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}