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

On initial page load run init before turbo:load has been fired #646

Merged
merged 10 commits into from
Nov 26, 2024

Conversation

indykoning
Copy link
Member

@indykoning indykoning commented Nov 15, 2024

This will make Rapidez initialize before marketing scripts, browser extensions and other scripts run.
Improving startup times of Rapidez.

Before:
image

After:
image

Currently as draft as we should figure out the best method/event to run this on in order not to impact LCP

@indykoning
Copy link
Member Author

indykoning commented Nov 18, 2024

After the last commit the LCP is no longer impacted.
We no longer fire before ALL browser extensions, but we do fire earlier.
After:
image

Also i've placed more in timeouts and animation frames, so they schedule their own tasks instead of putting it all on a task that's already taking too long

This is what it looks like without browser extensions now:
image

As you can see Vue bootup is even decoupled from the onload event. onload can be fired before or after vue has booted depending on external factors

@indykoning indykoning marked this pull request as ready for review November 18, 2024 16:38
@indykoning indykoning requested a review from royduin as a code owner November 18, 2024 16:38
document.addEventListener('turbo:load', init)
setTimeout(init)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific order of setTimeout and requestAnimationFrame ensures LCP is not impacted.
And ensures small task time for the turbo:load/evaluate script, and vue:loaded events by scheduling them all in their own task.

Using a setTimeout for both, a requestAnimationFrame for both, or executing this immediately and booting Vue in a requestAnimationFrame all has impact on the LCP

@royduin
Copy link
Member

royduin commented Nov 21, 2024

So this is still work in progress? Is it tested within a real project?

@indykoning
Copy link
Member Author

indykoning commented Nov 21, 2024

Yes it has been tested (though locally) with both a clean Rapidez installation, and a couple of real projects without issue.
Though i'm struggling with the tests

@royduin
Copy link
Member

royduin commented Nov 26, 2024

I'll change it to a draft, please mark it when it's ready to merge

@royduin royduin marked this pull request as draft November 26, 2024 08:43
@indykoning
Copy link
Member Author

It seems the tests were caused by the order that event listeners were being applied in.
Vue could not prevent the event listener for turbolinks causing a navigation before the vue events were fired.

Loading turbo lazily fixes this issue.

@indykoning indykoning marked this pull request as ready for review November 26, 2024 13:02
@royduin royduin merged commit c01f532 into rapidez:master Nov 26, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants