jarir-ahmed / universal-spa
A framework-agnostic Single Page Application (SPA) engine for PHP
Package info
github.com/jarir2020/universal-spa
Language:JavaScript
pkg:composer/jarir-ahmed/universal-spa
Requires
- php: >=7.4.0
This package is auto-updated.
Last update: 2026-05-24 20:40:24 UTC
README
A lightning-fast, zero-reload Single Page Application (SPA) engine for any PHP Framework (Laravel, CodeIgniter, Symfony, Slim, or even raw PHP).
Two Modes
This package empowers you with two distinct approaches:
1. HTML Mode (Zero Backend Required)
In this mode, the frontend JavaScript fetches the full HTML page, parses it in the browser using DOMParser, and swaps out the body.
Pros: Requires ZERO PHP changes. Works with static sites or any backend.
2. JSON Mode (Bandwidth Optimized)
In this mode, the PHP backend intercepts the response buffer, parses the HTML, and sends only the required parts (Title, Body, Scripts) as a tiny JSON object. Pros: Faster network transfer.
Installation
composer require jarir-ahmed/universal-spa
Setup (JSON Mode)
- Put this at the very top of your PHP application (e.g.,
public/index.phpor as a middleware):
\JarirAhmed\UniversalSpa\SpaEngine::start();
- Add
data-spa-contentto your main wrapper in your HTML layout:
<main data-spa-content> <!-- Your page content goes here --> </main>
- Add the
data-spaattribute to any links you want to feel instant:
<a href="/about" data-spa>About Us</a>
- Include the JS script and initialize it:
<script src="path/to/resources/js/jarir-spa.js"></script> <script> new JarirSpa({ mode: 'json' // or 'html' }); </script>
License
MIT