Vite Plugin
Thelazy option in the pages shorthand controls how page components are loaded. It defaults to true.
Manual Vite
You may configure code splitting manually using Vite’simport.meta.glob() function when not using the Inertia Vite plugin. Pass { eager: true } to bundle all pages, or omit it to lazy-load them.
Preloading the Initial Page
On the first visit to your application, the browser must download and execute your main JavaScript bundle before it knows which page component to load. You may avoid this extra round trip by passing the current page component to the@vite directive in your root template, which preloads the page component and its dependencies alongside your main bundle.
$page variable is available in your root template and contains the page object.
Link Headers
Laravel’sAddLinkHeadersForPreloadedAssets middleware, included in the Laravel starter kits, adds every preloaded asset to a Link response header, allowing the browser to start downloading them before parsing the HTML. Since the dependencies of the page component are included as well, this header may exceed your web server’s response header buffer on larger pages, causing the initial page load to fail. Subsequent Inertia visits are not affected, as they return JSON without rendering the root template.
You may limit the number of assets included in the header using the middleware’s using() method, which is available as of Laravel 12.12.
<link> tags rendered by the @vite directive, so removing the middleware entirely has little impact. Alternatively, you may increase your web server’s response header buffer, such as Nginx’s fastcgi_buffer_size directive, or proxy_buffer_size when proxying requests to Laravel Octane.
Webpack
To use code splitting with Webpack, enable dynamic imports with a Babel plugin:.babelrc file in your project with the following configuration:
resolve callback in your app’s initialization code to use import instead of require.