Download the PHP package jessegall/inertia-static-props without Composer
On this page you can find all versions of the php package jessegall/inertia-static-props. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package inertia-static-props
Inertia Static Props
Optimize Inertia.js applications by loading static data only during the first page load.
A Laravel package that improves performance by caching static data on the client side, reducing payload sizes and processing time for subsequent requests.
Table of Contents
- Introduction
- Installation
- Usage
- Manually Refreshing Static Props
- Adding Static Props to Component Renders
- How It Works
- License
Introduction
Inertia Static Props optimizes your Inertia.js application by loading static data only once during the initial page load. After that, static props are cached in the frontend and injected into the page props on every subsequent visit.
By using static props, you can significantly reduce the payload size and processing time for subsequent requests, leading to improved performance.
Installation
The package consists of two parts: a Laravel backend package and a frontend adapter.
Backend
Install the package via Composer:
The package will auto-register its service provider if you're using Laravel's package auto-discovery.
Otherwise, you can manually register the service provider:
Frontend
-
Install the frontend adapter via npm:
- Set up the plugin in your Inertia application:
Usage
You can share static props from anywhere in your application.
The most common place is in your HandleInertiaRequests
middleware, but this is not required:
The shared static props will always be available in the page props.
Thats it! The static props will be cached in the frontend and injected into the page props on every subsequent visit.
Manually Refreshing Static Props
Sometimes you need to refresh static props after certain actions, like changing the users locale, or when the user permissions change.
Adding Static Props to Component Renders
Though, not recommended, it is possible to include static props when rendering components.
[!WARNING]
Static props are only sent to the client during the initial page load.
When your controller is accessed after the initial page load, you'll need to reload the static props to ensure the static props are sent to the client.
How It Works
Behind the scenes, the package:
- Identifies props wrapped in
StaticProp
during the initial page load - Evaluates these props and sends them to the client
- Caches them in the frontend (browser)
- On subsequent requests, these props will NOT be resolved on the server and are removed from the response.
- The client-side adapter injects the cached props back into the page props before Inertia processes them, creating a seamless experience as if the server had sent them.
This results in smaller payloads and reduced server processing time for subsequent requests.
License
MIT
All versions of inertia-static-props with dependencies
inertiajs/inertia-laravel Version ^2.0
php Version ^8.2