Some data rarely changes, is expensive to compute, or is simply large. Rather than including this data in every response, you may use once props. These props are remembered by the client and reused on subsequent pages that include the same prop. This makes them ideal for shared data.Documentation Index
Fetch the complete documentation index at: https://inertiajs.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Creating Once Props
To create a once prop, use theInertia::once() method when returning your response. This method receives a callback that returns the prop data.
Forcing a Refresh
You may force a once prop to be refreshed using thefresh() method.
Refreshing from the Client
You may refresh a once prop from the client-side using a partial reload. The server will always resolve a once prop when explicitly requested.Expiration
You may set an expiration time using theuntil() method. This method accepts a DateTimeInterface, DateInterval, or an integer (seconds). The prop will be refreshed on a subsequent visit after the expiration time has passed.
Custom Keys
You may assign a custom key to the prop using theas() method. This is useful when you want to share data across multiple pages while using different prop names.
Sharing Once Props
You may share once props globally using theInertia::share() method.
shareOnce() method.
as(), fresh(), and until() onto the shareOnce method.
shareOnce() method in your middleware. The middleware will evaluate both share() and shareOnce(), merging the results.
Conditional Once Props
Some shared data is mostly stable but changes at specific moments, like the authenticated user. You may return a once prop while a user is authenticated, andnull otherwise. Sign in and sign out usually end with a redirect to a page that does not explicitly request the auth prop, so a remembered once value would go stale.
Returning null on signed-out requests overwrites the remembered user on every response, while returning a once prop when authenticated lets the client remember the user across visits.
Prefetching
Once props are compatible with prefetching. The client automatically includes any remembered once props in prefetched responses, so navigating to a prefetched page will already have the once props available. Prefetched pages containing an expired once prop will be invalidated from the cache.Combining with Other Prop Types
Theonce() modifier may be chained onto deferred, merge, and optional props.