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.

use Inertia\Inertia;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
      Inertia::version($version);

      // If you're using Laravel Mix, you can
      // use the mix-manifest.json for this.
      Inertia::version(function () {
          return md5_file(public_path('mix-manifest.json'));
      });
    }
}

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.