Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chron's avatar
Level 6

How to add loading screen in Laravel, Vue w/ Inertia

This would be easy if inertia is not involved but it is.

By the time the loading screen shows, the resources also has loaded so the loading screen only shows for a second.

//Loading.vue

<script setup>
	defineProps({ hasLoaded });
</script>
<template>
	<div v-show="hasLoaded">
		<img src="loading.svg"  />
		Loading...
	</div>
</template>
//Main.vue
<script setup>
	import { ref, onMounted } from "vue";
	import Loading from "./components/Loading";
	import Navigational from "./components/Navigational";

	const hasLoaded = ref(true);

	onMounted(() => {
		hasLoaded = !hasLoaded;
	})
</script>
<template>
	<Loading :hasLoaded="hasLoaded" />
	<Navigational />
	<slot></slot>
</template>
0 likes
2 replies
gych's avatar

If you want the loading screen to be displayed for a longer time, you can use timers, but personally, I would prefer faster loading speeds rather than intentionally slowing it down just to show the loading animation for longer.

You can also look at the documentation of the Inertia progress indicator and use that implementation. You can customize this and set a delay.

https://inertiajs.com/progress-indicators

Chron's avatar
Level 6

Thanks for responding but I don't want to delay loading times. I'm also getting a white flash while the page reloads so to remove, or at least, mitigate the flash, I just removed Loading from vue and just put it before laravel @inertia.

But I'm still open for cleaner approach.

Please or to participate in this conversation.