npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

phpspa-js

v1.1.9

Published

A lightweight, component-based PHP library for building Single Page Applications (SPAs) without relying on heavy frontend frameworks.

Downloads

33

Readme

⚡ phpspa-js

phpspa-js is the lightweight JavaScript runtime for phpSPA, a PHP framework that mimics Single Page Application behavior without the complexity of a frontend framework.

It handles client-side navigation, page transitions, script execution, component styling, and event hooks — all designed to work with dynamic content rendered from PHP.


🚀 Installation

You can include phpspa-js either via CDN or host it yourself.

✅ CDN (Recommended)

<script src="https://cdn.jsdelivr.net/npm/phpspa-js"></script>

🔧 Manual (GitHub)

Clone or download from the repo:

git clone https://github.com/dconco/phpspa-js.git

Then include it in your layout:

<script src="/path/to/phpspa-js/dist/phpspa.min.js"></script>

🌐 Usage

Once included, phpspa-js automatically enhances <Link /> tags with data-type="phpspa-link-tag" and enables seamless navigation between registered components.

You don’t need to do anything fancy — just generate links using your backend that look like this:

<a href="/dashboard" data-type="phpspa-link-tag">Dashboard</a>

🧠 Core API

📥 phpspa.navigate(url, mode = "push")

Navigates to a new route dynamically. Internally fetches the component content, updates the targetID, <title>, styles, and scripts.

  • url: Can be a string or URL object.
  • mode: "push" (default) adds a new history entry, "replace" modifies the current one.
phpspa.navigate("/profile", "replace");

↩️ phpspa.back(), phpspa.forward()

Handles SPA-style backward or forward navigation using browser history.

phpspa.back();     // like window.history.back()
phpspa.forward();  // like window.history.forward()

📌 Event System

Use phpspa.on() to register event hooks:

phpspa.on("beforeload", ({ route }) => {
    console.log("Navigating to", route);
});

phpspa.on("load", ({ route, success, error }) => {
    if (success) {
        console.log("Loaded:", route);
    } else {
        console.error("Failed to load", route, error);
    }
});

Available Events

| Event Name | Description | | ------------ | --------------------------------------- | | beforeload | Fired before route is loaded | | load | Fired after load is completed or failed |

Event callbacks receive an object:

{
  route: string,
  success?: boolean,
  error?: Error
}

🧩 Component Scripts

Each component can include inline scripts using:

<script data-type="phpspa/script">
    console.log("Component script ran");
</script>

These are dynamically executed when the component is loaded via phpspa.navigate() or browser navigation. They won’t run on initial page load unless rendered by PHP.


🎨 Component Styles

Components can also define scoped styles:

<style data-type="phpspa/css">
    .button { color: red; }
</style>

These styles are:

  • Appended to the <head> dynamically
  • Automatically cleaned up when navigating to another route

🧼 Scroll Restoration

phpspa-js supports native scroll restoration:

history.scrollRestoration = "auto";

This ensures each component can handle scroll behavior without interference.


📦 Built for Integration

This script is tightly coupled with phpSPA (PHP), and it's designed to work with its component system.


🔧 Development Notes

Structure

  • CDN build: phpspa.min.js
  • Event system: phpspa.on("load", ...)
  • History API used for SPA behavior
  • Graceful fallback when JS is disabled

📘 Docs & Links


📜 License

MIT © Dave Conco