Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track time of eager-loading Turbo Frames #12

Open
leonvogt opened this issue May 29, 2024 · 2 comments
Open

Track time of eager-loading Turbo Frames #12

leonvogt opened this issue May 29, 2024 · 2 comments
Labels
enhancement New feature or request Turbo

Comments

@leonvogt
Copy link
Owner

Track the time it takes for a eager-loaded (or lazy-loaded) Turbo Frames to load.
This information could be displayed in the Turbo Frame tab from the detail panel, or directly in the DOM besides the Turbo Frame info badge.

@leonvogt leonvogt added enhancement New feature or request Turbo labels May 29, 2024
@leonvogt
Copy link
Owner Author

leonvogt commented May 31, 2024

Attempt MutationObserver:

listenForLazyLoadedFrames() {
  const turboFramesWithSrc = document.querySelectorAll("turbo-frame[src][busy]")
  turboFramesWithSrc.forEach((frame) => {
    const observer = new MutationObserver((mutations) => {
      mutations.forEach((mutation) => {
        if (mutation.attributeName === "complete") {
          const timeEnd = new Date().getTime()
          const timeDiff = timeEnd - this.devTool.initializedAt
          console.log(`Frame ${frame.id} loaded in ${timeDiff}ms`)
        }
      })
    })
    observer.observe(frame, { attributes: true })
  })
}

Tests (time in ms)

Our time Time meassured by Chrome Network Tools Difference
450 432 18
585 572 13
519 498 21
243 458 -215
503 702 -199
251 442 -191
270 403 -133
794 850 -56
384 326 58
363 356 7
823 889 -66

Average difference: -67,55ms

@leonvogt
Copy link
Owner Author

leonvogt commented May 31, 2024

Attempt Event turbo:before-frame-render:

listenForLazyLoadedFrames() {
  document.addEventListener("turbo:before-frame-render", (event) => {
    const timeEnd = new Date().getTime()
    const timeDiff = timeEnd - this.devTool.initializedAt
    console.log(`Frame: ${event.target.id} loaded in ${timeDiff}ms`)
  })
}

Tests (time in ms)

Our time Time meassured by Chrome Network Tools Difference
395 585 -190
415 502 -87
496 508 -12
1480 1510 -30
673 673 0
349 525 -176
395 412 -17
725 769 -44
668 693 -25
367 555 -188
461 660 -199

Average difference: -88,00ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Turbo
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant