WordPress WASM
github.com
github.com
Initially these are more of a “backed data” type app, with no offline public writes. [0]
The next step is to have local/offline SQLite to server syncing, enabling writes while offline that are synced back to the server on reconnection. This would inherently be eventually consistent and brings its own issues with relational data integrity, however the SQLite Session Extension could be I good way to build such a system [1]
The alternative is a new data store based on CRDTs (conflict free merging of offline edits), there are some exciting developments happening in that area. I have seen it suggested that the SQLite session extension is almost a crdt if you squint at it.
1.) How would the auto-incremented ID fields be merged in such a system?
2.) How are unique constraint violations handled?
Basically for learning/interactive tutorials, trying out something quickly in different PHP versions (which is cumbersome right now), secure and easy demos for themes and plugins.
Would also love to see it for Java, Go, Perl, Sed, and Awk :)
What if Intelli-J could run in the browser? Yes please.
I bet some of these even already exist. What a time to be alive, 15 years ago I'd never have guessed Javascript could evolve into this!
[0] https://www.crunchydata.com/blog/crazy-idea-to-postgres-in-t...
[1] https://news.ycombinator.com/item?id=32498435 (August 22, 2022; 814 points, 172 comments)
^ n.b. Submitted by @samwillis
I hope to change how learning, using, and contributing to WordPress looks like. This writeup explores how WASM WordPress works and why it's useful:
https://make.wordpress.org/core/2022/09/23/client-side-webas...
Here's a few possible applications: try a theme without affecting your current website, have live themes and plugins demos right in the directory, enable first contributions directly on wordpress.org without any setup steps, learn WordPress in the browser, or replay and debug failed tests right in the CI.
Technically most of these things are possible today with a specialized backend. The problem is that it's either expensive and time-consuming to maintain, like a fleet of custom WP instances, or limited, like iframing a preconfigured 3rd party solution. WASM-based solution is open-source, cheap to run, and doesn't seem to have deal-breaking limitations.
I wouldn't run production websites on this just yet, as it sometimes crashes in Chrome and the bundle size is 50MB+, but both problems can be solved. Once they are, this will be so much more than just a cool tech demo.
This is seriously impressive -- I think we're getting a glimpse of a world where people can really run server side apps on their computers easily.
Add an app store and the web will have finished becoming the platform that everyone has been suspecting it is.
Monocultures are susceptible to pests and diseases
And I am sure a severe bug in Qt will also affect almost everyone, no different from the Chromium situation. And I trust the Chromium/Electron community more than the random "another cross-platform UI framework" that pops up on hacker news that probably will not be maintained in a year. (I am some people don't like this sentence but they have to face the fact.)
> Add an app store and the web will have finished becoming the platform that everyone has been suspecting it is.
Basically what we need now is a user-side "app store" that downloads apps packaged as WASM and runs them!
Honestly this setup could probably work today, use something like Tauri[0] to build a simple app-store like experience. When someone installs an app, this thing downloads the WASM, and runs it with the necessary linked modules (local file access, network).
Then, you can spin up a new window that is the new application, and keep it running/do whatever else users would expect. I mean you could even launch the apps standalone/separate processes as well so that people can close the original one (or put it to tray, whatever).
This could easily be like snap/flatpak but even better in some ways. Browser technology is almost assured to always be moving forward and getting more powerful/impressive because of the large interests involved.
Consumers don't use CLIs to install things.
AbsurdSQL is an incredible hack, but is a hack at best.
There is a new api, File System Access and the “origin private file system”[0], coming to browsers that has been design specifically with WASM SQLite in mind. I believe the Chrome team have been collaborating with the SQLite team to ensure it will work well. Once this drops it’s going to bring a lot of innovation.
0: https://web.dev/file-system-access/#accessing-files-optimize...
This is more of a tech demo and test environment than something that would work as an alternative to server-side WordPress - since if you are using a CMS you generally want the results to be visible to people other than you!
It's very, very cool though.
https://make.wordpress.org/core/2022/09/23/client-side-webas...
To answer your questions directly:
WebAssembly is the magic sauce that transforms server-side code into client-side code. MySQL unfortunately is not yet supported by WebAssembly, so I applied a plugin that adds SQLite supports to WordPress [0]. The WebAssembly application has its own in-memory filesystem that lives in a specific browser tab and is scraped as soon as you close it.
So – technically it exposes db credentials, and even the entire DB, but that you are the only user of that DB so it's okay.
> What would the backend look like
The only backend is a static file server where the code and the database live. Your browser downloads a copy of the database and allows you to modify it in the current tab, but the updates are never saved back to the server.
The database also runs on the client in wasm (sqlite).
But it's utterly useless if you want to put a blog online as it only runs locally in the browser and nobody else will see the posts.
In this way the server could serve a cached page on first request, then the wasm file would be downloaded. From then the whole rendering could be client side, while still fetching data from the remote DB. This could significantly speed up things for users.
It won’t prevent obvious security bugs in the PHP code though, which arguably is the most important attack vector for spammers trying to post stuff on your WordPress installation
Oftentimes I run some CMS in some private network and then deploy a static build somewhere else
The forest is shrinking the time and distance between code we care about and visualizing the results. WASM and an in-browser environment is the tree. Even for experienced devs it's not always readily available to have a web server, PHP, a database, and WordPress running where you can quickly make a change and test it out or demonstrate it to others.
This makes it possible to ship a WordPress site as a demo site (with pre-filled content and structure) where anyone can show off their WordPress plugin or theme without needing to have a backend or worrying about securing it.
Aside from that - this thing uses SQLite for a specific reason - the browser can't connect directly to a remote DB, so any content you create in this instance is visible to precisely no one else. As such, it's certainly not an answer to actual publishing use cases either.
If it worked fully of course, which it currently doesn't.
Also cloudflare has D2, which is based on SQLITE, but has yet to launch.
I think it should launch by the end of this year.
Endless possibilities!
https://adamziel.github.io/index.html
https://adamziel.github.io/tutorial.html
It also lives on netlify: https://fanciful-gnome-a4edc4.netlify.app/