PHPackages                             saakiiib/laravel-spa - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. saakiiib/laravel-spa

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

saakiiib/laravel-spa
====================

Zero-reload SPA engine for Laravel Blade — no jQuery, no Livewire, no Inertia.

v1.0.0(3w ago)301↑33.3%MITJavaScriptPHP ^8.1

Since Jun 29Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/saakiiib/laravel-spa)[ Packagist](https://packagist.org/packages/saakiiib/laravel-spa)[ RSS](/packages/saakiiib-laravel-spa/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (10)Used By (0)

Laravel SPA — by [Sakib](https://github.com/saakiiib)
=====================================================

[](#laravel-spa--by-sakib)

By default, every link click in Laravel loads a full new page — HTML, CSS, JS, fonts, everything re-downloads. SPA navigation skips that. Only the content changes, the rest stays. Faster, smoother, no white flash between pages.

Most Laravel SPA solutions force you to either abandon Blade entirely (Inertia) or add jQuery (pjax). This package adds that same speed on top of your existing Blade views — no rewrite, nothing changes except how fast it feels.

---

Quick Start
-----------

[](#quick-start)

```
composer require saakiiib/laravel-spa
php artisan vendor:publish --tag=spa-assets
```

> Add `/public/vendor` to your `.gitignore` to avoid committing published assets.

> **Updating?** When you run `composer update`, the published `spa-engine.js` in `public/vendor/` does **not** auto-update — Composer only updates the package source, not previously published assets. Re-publish with the `--force` flag to pull the latest fix/version in:
>
> ```
> php artisan vendor:publish --tag=spa-assets --force
> ```
>
>
>
> Skipping this means you'll keep running an old `spa-engine.js` even after upgrading the package version.

---

Setup — `@extends` / `@section`
-------------------------------

[](#setup--extends--section)

**1. Layout file**

Add `@spaContent` to your content wrapper and `@spaEngine` before ``. Make sure `@yield('script')` comes after `@spaEngine`.

```

    @yield('content')

@spaEngine
@yield('script')
```

**2. Navigation links**

Add `@spa` to links you want SPA navigation on. Links without `@spa` do a normal full reload.

```
Home
About
Logout
```

**3. Controller**

```
public function home()
{
    return spa('pages.home');
}

public function about()
{
    return spa('pages.about', compact('data'));
}
```

**4. Page views — no changes needed**

```
@extends('layouts.app')

@section('title', 'Home')

@section('style')

        .hero { background: #1a3c6e; color: #fff; padding: 60px; }

@endsection

@section('content')

        Welcome

@endsection

@section('script')

        console.log('page loaded');

@endsection
```

---

Setup — `x-layout` components
-----------------------------

[](#setup--x-layout-components)

**1. Layout component**

Add `@spaContent` to your content wrapper and `@spaEngine` before ``.

```

        /* global styles */

    {{ $style ?? '' }}

        {{ $slot }}

        /* global scripts */

    @spaEngine
    {{ $script ?? '' }}

```

**2. Navigation links** — same as above, add `@spa`:

```
Home
Logout
```

**3. Controller** — same as above:

```
public function home()
{
    return spa('pages.home');
}
```

**4. Page views**

```

            .hero { background: #1a3c6e; color: #fff; padding: 60px; }

        Welcome

            console.log('page loaded');

```

---

Global JavaScript &amp; Third-Party Plugins
-------------------------------------------

[](#global-javascript--third-party-plugins)

Page-specific scripts in `@section('script')` run automatically on every navigation — no extra setup needed.

For global scripts that need to run on every page, place your JS file after `@spaEngine`:

```
@spaEngine

@yield('script')
```

In `app.js`, use `spa:loaded` to re-initialize plugins after each navigation. Here's an example with Select2:

```
document.addEventListener('spa:loaded', function () {
    $('.select2').select2();
});
```

For event listeners, attach them to `document` once — they work on every page automatically:

```
document.addEventListener('click', function (e) {
    if (e.target.matches('.delete-btn')) {
        // works on every page
    }
});
```

---

What works out of the box
-------------------------

[](#what-works-out-of-the-box)

- URL updates, back/forward button, refresh, direct links — all work
- Per-page styles and scripts load and unload on every navigation
- Session expiry redirects cleanly instead of breaking
- Hover prefetch — pages start loading before you even click
- Works with both `@extends` and `x-layout`
- `spa:loaded` event fires after every navigation for global plugin re-initialization

---

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, 12, or 13

---

Contributing
------------

[](#contributing)

Found a bug or want to improve something? PRs are welcome on [GitHub](https://github.com/saakiiib/laravel-spa).

---

License
-------

[](#license)

MIT — [Sakib](https://github.com/saakiiib)

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance91

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

9

Last Release

26d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fce35f81666da245757dea18e1381eb8586eea4cad02b2b3a8f02fa73063ceac?d=identicon)[nsakib](/maintainers/nsakib)

---

Top Contributors

[![saakiiib](https://avatars.githubusercontent.com/u/128025804?v=4)](https://github.com/saakiiib "saakiiib (9 commits)")

### Embed Badge

![Health badge](/badges/saakiiib-laravel-spa/health.svg)

```
[![Health](https://phpackages.com/badges/saakiiib-laravel-spa/health.svg)](https://phpackages.com/packages/saakiiib-laravel-spa)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
