Laravel 5.6 Blade Page Loading Spinner
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Implementing a Smooth Loading Experience in Laravel Blade: The Spinner Solution
As a senior developer, I understand that a seamless User Experience (UX) is just as critical as functional code. A slow-loading application frustrates users, and nothing breaks immersion faster than a blank screen during a transition. In the context of a Laravel 5.6 project, where we focus on robust backend logic, adding a visual indicator—a loading spinner—is the final piece that elevates the experience to production quality.
You are looking for the easiest way to implement this using an asset file (loading.gif) during page loads. While there isn't one single magic function built into Blade for this specific task, the solution lies in combining standard front-end techniques (HTML, CSS) with Laravel’s templating capabilities.
Here is a comprehensive guide on how to implement a professional loading spinner in your Laravel application.
The Strategy: Overlaying the Interface
The most effective way to show a loading state is to create a full-screen overlay that sits above all other content. This forces the user’s attention onto the loading process and visually communicates that the system is working, rather than just waiting passively. We will use CSS for positioning and ensure our spinner is centered perfectly.
Step 1: Preparing Your Assets
Ensure your loading.gif is correctly placed in the public directory (e.g., public/assets/loading.gif). This ensures it is accessible via a URL when referenced in Blade.
Step 2: Styling the Spinner with CSS
We need CSS to make the overlay cover the entire viewport and position the GIF centrally. This ensures responsiveness and visual appeal.
/* styles.css (or within your main layout file) */
.loading-overlay {
position: fixed; /* Stays in place even when scrolling */
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.9); /* Semi-transparent white background */
display: flex;
justify-content: center; /* Center horizontally */
align-items: center; /* Center vertically */
z-index: 9999; /* Ensure it sits above all other content */
}
.spinner {
width: 50px; /* Adjust size as needed */
height: 50px;
animation: spin 1s linear infinite; /* Apply the spinning animation */
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
Step 3: Integrating into the Laravel Blade Layout
Now, we integrate this CSS and HTML structure into your main layout file (e.g., resources/views/layouts/app.blade.php). This ensures that every page load—whether it's a full refresh or an AJAX transition—will respect this visual indicator.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Laravel App</title>
<link rel="stylesheet" href="{{ asset('css/styles.css') }}">
</head>
<body>
{{-- THE LOADING OVERLAY --}}
@if (session('loading'))
<div class="loading-overlay">
<img src="{{ asset('assets/loading.gif') }}" alt="Loading...">
</div>
@endif
{{-- Rest of your page content goes here --}}
<div class="content">
<!-- Page specific content -->
</div>
</body>
</html>
Step 4: Triggering the Loading State in Your Controller
The final, crucial step is controlling when this spinner appears. In a typical Laravel setup, if you are loading data that takes time (like fetching complex reports or processing queues), you would set a session flag in your controller before rendering the view.
Example Controller Logic:
// Example: In your PostController@show method
public function show($id)
{
// Simulate a long-running process
sleep(3);
// Set the session flag to tell the Blade file to display the spinner
session()->flash('loading', true);
return view('posts.show', ['post' => Post::find($id)]);
}
By checking session('loading') within your main layout, you create a robust system where any time a heavy operation is underway, the user sees a clear, animated indicator. This approach keeps your Laravel application clean while delivering a superior front-end experience, aligning with modern development practices seen in frameworks like Laravel. For further insights into building scalable applications, always refer to the official documentation at laravelcompany.com.
Conclusion
Implementing a loading spinner is not just a visual flourish; it’s an essential part of creating professional, performant web applications. By leveraging the power of Blade for conditional rendering and standard CSS for positioning, you can easily add this functionality to any Laravel project, ensuring that your users always have a clear understanding of what is happening behind the scenes. Focus on clean separation of concerns—keep your backend logic separate from your presentation layer, just as we do when structuring projects according to Laravel's principles.