-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
perf: pre transform requests while opening the browser #12809
perf: pre transform requests while opening the browser #12809
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Couldn't this also work when |
@Akryum when --open is used, we are sure of what the first request will be. If it isn't used, then we could also send a request for |
Maybe the last opened route can be saved as it is very likely to be the one being loaded by the user when her browser is opened again. |
That's an interesting proposal @Akryum. We're discussing with @bluwy how the API for warmup would look like and my feeling is that having too much magic here wouldn't be needed if there is a good way to configure Vite (and if this is mostly taken care of by frameworks). So I would prefer to keep the strategy in the PR simple. We still need to check how it will fit in the big picture, but I think that whatever the API is going to look like, this addition is a good nice to have. We probably will only do it if custom warmup is not defined by the user, so I don't think it would interfere with it. |
For usage without |
We discussed this PR on the last team meeting, and we agreed on moving forward with it in Vite 5. |
Description
There is a ~500-600ms blank when opening the browser where we only run the scanner and optimize step (these two are off the main thread for the most part and are generally really fast so we can still run other things in parallel).
@bluwy developed vite-plugin-warmup, which we are trying to include directly in core so frameworks can start the pre-process earlier.
This PR is complementary to a future warmup and implements an optimization that doesn't require configuration so users can take advantage of it directly. When the
--open
flag is used, we know what is the first request that the browser will emit. So, no matter what framework is used to process entry points (or if our index HTML middleware kicks in) we can do the same request upfront. For this to work in frameworks that replace the index HTML middleware, they should also callserver.transformRequest(url)
for the scripts they find. This is a good idea in general, independent of this PR, so we should push for that across the ecosystem.One caveat of the approach in this PR is that the entry point will be processed twice. I think this isn't a problem because it is what normally occurs when several tabs are opened and the server is reloaded. We could add caching to the index HTML middleware but I don't know if the complexity is worth it because processing the HTML during dev is a really fast operation.
What is the purpose of this pull request?