Prefetch an Inertia link

prefetch on a Link loads a GET page before the click. Do not prefetch a POST, a logout, or a page the user cannot open.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/inertia-link-prefetch-vue.md
prefetch on a Link loads a GET page before the click. Do not prefetch a POST, a logout, or a page the user cannot open.
Do not prefetch a POST, a logout, or a page the user cannot open.
Do not prefetch a logout URL.
Do not prefetch a URL the policy will reject.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Inertia prefetch” put prefetch on every link, including ones that post. Prefetch sends a GET. Use it for a page the user is about to open.

TL;DR

  • prefetch on a Link loads a GET page before the click.
  • Do not prefetch a POST, a logout, or a page the user cannot open.
  • Do not prefetch a logout URL.
  • Do not prefetch a URL the policy will reject.

Who it's for: Laravel + Vue developers on Inertia

Applies to: Laravel 13 · Inertia 3 · Vue 3

The fix#

vue
<script setup lang="ts">
import { Link } from "@inertiajs/vue3";
</script>

<template>
  <Link href="/posts" prefetch>Posts</Link>
</template>

The default waits for a hover. The next click is faster because the response is already in memory. The pagination guide is the list this link usually opens. Prefetch does not change that page’s props.

What to avoid#

Gotcha

Do not prefetch a logout URL. Logout is a POST, and a GET prefetch would either fail or, worse, hit a route you mistakenly registered as GET. Do not prefetch a URL the policy will reject. You would be caching a 403 for a hover.

Do not prefetch a page that runs a write in its controller. A controller that writes on GET is already a bug. Prefetch makes it happen on hover.

FAQ#

How do I prefetch an Inertia link?

prefetch on a Link loads a GET page before the click. Do not prefetch a POST, a logout, or a page the user cannot open.

What goes wrong with Inertia prefetch?

Many developers put prefetch on every link, including ones that post. Do not prefetch a logout URL.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.