Skip to content

Commit 18bc0f0

Browse files
authored
loaf (#3627)
1 parent 88c7dfc commit 18bc0f0

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

src/static/js/send-web-vitals.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,35 @@ function sendWebVitals() {
2323
// LoAFs that intersect with the event.
2424
return entry.startTime < (loaf.startTime + loaf.duration) && loaf.startTime < (entry.startTime + entry.duration);
2525
}).forEach(loaf => {
26+
const loafEndTime = loaf.startTime + loaf.duration;
2627
loaf.scripts.forEach(script => {
27-
const totalDuration = script.startTime + script.duration;
28-
if (totalDuration > loafAttribution.debug_loaf_script_total_duration) {
29-
loafAttribution = {
30-
// Stats for the LoAF entry itself.
31-
debug_loaf_entry_start_time: loaf.startTime,
32-
debug_loaf_entry_end_time: loaf.startTime + loaf.duration,
33-
debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration,
34-
debug_loaf_entry_render_duration: loaf.renderStart ? loaf.startTime + loaf.duration - loaf.renderStart : 0,
35-
debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0),
36-
debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0,
37-
debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loaf.startTime + loaf.duration - loaf.styleAndLayoutStart : 0,
38-
39-
// Stats for the longest script in the LoAF entry.
40-
debug_loaf_script_total_duration: totalDuration,
41-
debug_loaf_script_compile_duration: script.executionStart - script.startTime,
42-
debug_loaf_script_exec_duration: script.startTime + script.duration - script.executionStart,
43-
debug_loaf_script_invoker: script.invoker,
44-
debug_loaf_script_type: script.invokerType,
45-
debug_loaf_script_source_url: script.sourceURL,
46-
debug_loaf_script_source_function_name: script.sourceFunctionName,
47-
debug_loaf_script_source_char_position: script.sourceCharPosition,
48-
49-
// LoAF metadata.
50-
debug_loaf_meta_length: longAnimationFrames.length,
51-
}
28+
if (script.duration <= loafAttribution.debug_loaf_script_total_duration) {
29+
return;
30+
}
31+
loafAttribution = {
32+
// Stats for the LoAF entry itself.
33+
debug_loaf_entry_start_time: loaf.startTime,
34+
debug_loaf_entry_end_time: loafEndTime,
35+
debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration,
36+
debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0,
37+
debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0),
38+
debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0,
39+
debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0,
40+
41+
// Stats for the longest script in the LoAF entry.
42+
debug_loaf_script_total_duration: script.duration,
43+
debug_loaf_script_compile_duration: script.executionStart - script.startTime,
44+
debug_loaf_script_exec_duration: script.startTime + script.duration - script.executionStart,
45+
debug_loaf_script_source: script.sourceLocation || script.invoker || script.name, // TODO: remove after Chrome 123
46+
debug_loaf_script_type: script.invokerType || script.type, // TODO: remove `|| script.type` after Chrome 123
47+
// New in Chrome 122/123 (will be null until then)
48+
debug_loaf_script_invoker: script.invoker,
49+
debug_loaf_script_source_url: script.sourceURL,
50+
debug_loaf_script_source_function_name: script.sourceFunctionName,
51+
debug_loaf_script_source_char_position: script.sourceCharPosition,
52+
53+
// LoAF metadata.
54+
debug_loaf_meta_length: longAnimationFrames.length,
5255
}
5356
});
5457
});

src/templates/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta http-equiv="origin-trial" content="AqqBKXKVFUu6Op5aphalxMRl8CECiZ0BVlee+zWMM1E9R6oLnNQPRIXd5F8gEYxahMwEzEjOYKzA3Nf6jIc08AEAAAB0eyJvcmlnaW4iOiJodHRwczovL2h0dHBhcmNoaXZlLm9yZzo0NDMiLCJmZWF0dXJlIjoiTG9uZ0FuaW1hdGlvbkZyYW1lVGltaW5nIiwiZXhwaXJ5IjoxNzE2OTQwNzk5LCJpc1N1YmRvbWFpbiI6dHJ1ZX0=">
78
{% block head %}
89
<title>{% block title %}The Web Almanac{% endblock %}</title>
910
<link rel="stylesheet" href="{{ get_versioned_filename('/static/css/normalize.css') }}">

0 commit comments

Comments
 (0)