PicoSPA makes Multi-Page Applications (MPAs) feel a bit more like Single-Page Applications (SPAs) — without changing your architecture. (used to be named SPAish)
  • JavaScript 66.4%
  • HTML 26.2%
  • CSS 5.9%
  • Shell 1.5%
Find a file
2026-01-15 17:07:39 +01:00
.github/workflows Installed playwright 2025-06-12 11:32:56 +02:00
docs Add figcaption to the first demos. 2026-01-15 17:07:39 +01:00
src Build and document the navigation.js 2026-01-12 20:40:35 +01:00
tests Make the grid lines render with the proper positioning. 2025-12-01 17:33:54 +01:00
.gitignore Installed playwright 2025-06-12 11:32:56 +02:00
CHANGELOG.md Build and document the navigation.js 2026-01-12 20:40:35 +01:00
docker-compose.yml Provide a prod.sh so in prod ./prod.sh update will do the job of building the latest. 2025-08-16 12:19:47 +02:00
LICENSE A lot of renaming in various docs files. 2025-08-16 10:56:32 +02:00
package-lock.json Add watch to continuously build docs. 2025-10-17 20:36:35 +02:00
package.json Organize todos and rename to date based version. 2026-01-12 18:51:59 +01:00
playwright.config.js Installed playwright 2025-06-12 11:32:56 +02:00
prod.sh This is how to use docker-compose in prod. 2025-08-16 12:23:04 +02:00
README.md Upgrade CDN URL to this version. 2026-01-12 20:41:00 +01:00

PicoSPA

PicoSPA - progressive enhancer for your MPA, make it feel PicoSPA.

Minified bundle size really open source License npm version

PicoSPA makes Multi-Page Applications (MPAs) feel a bit more like Single-Page Applications (SPAs) — without changing your architecture.

It's a small, framework-agnostic JavaScript library that allows you to:

  • Restore scroll positions across navigations
  • Reopen <details> elements after reload
  • Toggle and restore color schemes
  • Add anchors to headings
  • Store all state in sessionStorage
  • It adds no dependencies, weighs ~2KB minified

Use it with a <script> tag and enhance your site with just a few lines.

💡 Why?

MPAs often lose state (scroll, UI toggles, etc.) between page loads. SPAs often come with huge frameworks and complexity, size and speed overhead without much gain.
PicoSPA helps you preserve these micro-interactions without rewriting your site. See how kokoanalytics uses exactly this same approach.

🚀 Getting Started

Include via a script tag at the end of your page, or at least after the DOM nodes referred to have been rendered.

<script src="https://cdn.jsdelivr.net/npm/@pic0/spa@2026.1.12/_dist/picospa.min.js"></script>
<script>
  // Restore scroll position of the page, useful e.g. when filtering/sorting data, big forms, comments, threads, ...
  picospa.scroll.restore();
  
  // Reopen the <details> on page changes or when coming back to the page.
  picospa.details.reopen();
  
  // Restore the color scheme, e.g. light or dark mode.
  picospa.colorScheme.restoreLast();
  
  // Add anchors to headings, so you can link to them.
  picospa.section.addAnchors();
</script>

<p>Toggle the color scheme.</p>
<button onclick="picospa.colorScheme.toggle();">Toggle Color Scheme</button>

Development

Setup

  • npx playwright install to install the browsers needed for the tests

Run the tests

  • npm run test:serve (in a console) to start the test server that will be needed for running the playwright tests
  • npm run test (in another console) to run the playwright tests Why run it in two consoles? I just do it like that, so I can also open and look at test files directly in the browser, e.g. http://localhost:3000/test/section.html to see the section tests.
  • npm run test:fast to run the tests only in chromium, which reduces the number of tests and browsers to run, to get faster feedback