Asset versioning

One common challenge with single-page apps is refreshing site assets when they've been changed. Inertia makes this easy by optionally tracking the current version of your site assets. In the event that an asset changes, Inertia will automatically make a hard page visit instead of a normal ajax visit on the next request.

Configuring

To enable automatic asset refreshing, you simply need to tell Inertia what the current version of your assets is. This can be any string (letters, numbers, or a file hash), as long as it changes when your assets have been updated.

/*
|----------------------------------------------------------------
| Via the HandleInertiaRequests middleware (recommended)
|----------------------------------------------------------------
*/

class HandleInertiaRequests extends Middleware
{
    public function version(Request $request)
    {
        return parent::version($request);
    }
}

/*
|----------------------------------------------------------------
| Manually
|----------------------------------------------------------------
*/

use Inertia\Inertia;

Inertia::version($version);
Inertia::version(fn () => $version); // Lazily
The HandleInertiaRequests middleware provides a sensible default for Laravel applications, which uses either a hash of the "app.asset_url" config value or the mix-manifest.json file.

Cache busting

Asset refreshing in Inertia works on the assumption that a hard page visit will trigger your assets to reload. However, Inertia doesn't actually do anything to force this. Typically this is done with some form of cache busting. For example, appending a version query parameter to the end of your asset URLs.

If you're using Laravel Mix, you can do this automatically by enabling versioning in your webpack.mix.js file.