users and companiesprops are passed to the page component. However, on subsequent visits to the same page (maybe to filter the users), you can request only the users data from the server without requesting the companies data. Inertia will then automatically merge the partial data returned from the server with the data it already has in memory client-side.
Partial reloads only work for visits made to the same page component.
Only Certain Props
To perform a partial reload, use theonly visit option to specify which data the server should return. This option should be an array of keys which correspond to the keys of the props.
Except Certain Props
In addition to theonly visit option you can also use the except option to specify which data the server should exclude. This option should also be an array of keys which correspond to the keys of the props.
Router Shorthand
Since partial reloads can only be made to the same page component the user is already on, it almost always makes sense to just use therouter.reload() method, which automatically uses the current URL.
Using Links
It’s also possible to perform partial reloads with Inertia links using theonly property.
Lazy Data Evaluation
For partial reloads to be most effective, be sure to also use lazy data evaluation when returning props from your server-side routes or controllers. This can be accomplished by wrapping all optional page data in a closure.Inertia::optional() method to specify that a prop should never be included unless explicitly requested using the only option:
Inertia::always() method to specify that a prop should always be included, even if it has not been explicitly required in a partial reload.
| Approach | Standard Visits | Partial Reloads | Evaluated | |
|---|---|---|---|---|
User::all() | Always | Optionally | Always | |
fn () => User::all() | Always | Optionally | Only when needed | |
Inertia::optional(fn () => User::all()) | Never | Optionally | Only when needed | |
Inertia::always(fn () => User::all()) | Always | Always | Always |