-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Add Inertia::shareOnce() #37
Comments
I can see why this might be useful. One thing to consider would be how to "re-share" information that you have shared with the proposed For example, if you are sharing user details the once and they updated their username, email, name etc you would want that to then be re-shared. So in that instance the implementation would need to overrule the request header saying that the information is already on the client side. |
yep, re-share is a bit tricky, not sure if there is an elegant solution. |
It sounds more like something that would be on the client side. Perhaps on the client side you could do something like |
@reinink would like to know your thoughts on it. |
Hey folks! My gut reaction is that this feels like too much complexity for what you gain in performance. Passing the currently authenticated user on each request is adding very little overhead, and typically this shared data is pretty minimal. For most apps it will include:
I like to think of Inertia like a server-side framework. With a classic server-side framework, literally each page load you send the entire site template on each request, which includes the currently authenticated user (ie. in the header). And, that's a totally accepted way of doing things. So passing a little extra JSON in each Inertia request seems fine too. In fact, it's obviously way better than a classic server-side rendered app, since the entire template isn't being resent each time. This is something we can always revisit in the future. 💪 |
If I'm not mistaken, Inertia::share() adds share data to each response. However, in most of the case we only need to fetch the shared data once, for example, auth user usually won't change.
I was wondering if we can add an
shareOnce
method to avoid repeatedly sending share data. This implies that server need to store a state telling if the data is shared already. To avoid using session/cookie, we might need to pass some meta data in request/response. Here is a raw idea in the context of vuethis.$page
)It adds complexity, but it can reduce lots of unnecessary payloads. I'd love to do some experiment and create a PR if this feature request is accepted. pls let me know your thoughts.
The text was updated successfully, but these errors were encountered: