theoretic Posted 6 hours ago Posted 6 hours ago Hi all, JAMstack and static site generators are the way to show the world you’re a truly modern developer doing things right. ProcessWire is from another galaxy, of course... but come on, why not bring it into the SSG reality? 😉 StaticPages turns ProcessWire into a kind of static site generator and keeps everything good ProcessWire gives us: easy content creation and management, the page tree, fields, templates, the admin your clients already know. No build step, no separate deploy pipeline for content. How it works On every page request, StaticPages creates a dedicated HTML file, /about/team/ becoming /about/team/index.html. From then on the web server serves that file directly, as if there were no ProcessWire behind it: no PHP, no database, no bootstrapping. Files are generated lazily, on the first visit, so there is nothing to build and nothing to forget to rebuild. Don’t worry about file invalidation, exceptions, form submissions, CSRF and the other stuff: StaticPages handles it all. You can also fine-tune it to make static files only where they are truly needed. Invalidation: a save deletes only what went stale While a page renders, the module records what the render depended on: every page it loaded, and every find() it ran, by template, parent or ancestor. Saving a page then deletes only the files that loaded it, or ran a find it may have entered or left. Edit a news item, and the item, the news listing, the home page teaser and the menu linking to it are cleared. The rest of the site stays cached. Deletion runs after the response is sent, so the editor never waits. Editing an unpublished draft deletes nothing. Renames and moves clear the descendants too. Everything is wiped when a change has no page save to hang on: the config of a listed module is saved (SettingsFactory and friends); a tracked template or asset file changed; a page with a template you list is saved, or a field you list changes, for output from findRaw(), WireCache or raw SQL; a language page is saved. Exceptions: what never becomes a static file Pages viewed by logged-in users: you edit and preview live, visitors get static HTML. Form submissions (POST), requests with GET variables, ajax requests, pagination beyond page 1. Non-200 responses and the 404 page. Requests carrying cookies you list (currency, region, consent...), and responses that set a cookie or send a Vary header. Templates and directories you exclude. CSRF tokens are stripped from cached markup by configurable regexes, since one static file is served to everybody. If the module seems to do nothing, turn on Log skipped pages and the log will tell you why. Spoiler: you’re logged in. 😉 Server setup The web server has to be told about the files. On Apache, add these rules above ProcessWire’s last rewrite rule in .htaccess: RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{QUERY_STRING} ^$ RewriteCond %{REQUEST_FILENAME}/index.html -f RewriteRule ^(.+)/$ /$1/index.html [L] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+)$ index.php?it=$1 [L,QSA] The home page needs a pair of rules of its own, and multilingual sites keyed by host name need a little more. The README has all of it. For deploy scripts $sp = $modules->get('StaticPages'); $sp->checkTrackedPaths(true); // templates changed? wipe at script end $sp->wipeCaches(); // wipe every indexed file now $sp->wipeCaches(true, true); // list what a full scan would delete, delete nothing Beta, but battle tested StaticPages is still a beta release, though it is battle tested and runs on many of my projects. It stays beta because it creates and deletes files in the webroot, and that is potentially dangerous. So stay aware and use it carefully: Take a full backup before the first use. Run a Dry run first: it lists everything a wipe would delete and deletes nothing. The module is careful on its side too: Writes are atomic, so a visitor never gets a half-written page. Deletes touch only files named like the static file, below the site root, outside protected directories. A full disk scan walks only the directories that are static copies of pages. Good to know A static file is served without PHP, so headers sent with header() (CSP, Referrer-Policy...) reach only the first visitor. Put them in the server config. The dependency index lives in three small database tables. Without the CREATE privilege, the module falls back to wiping everything on every save. It’s a drop-in upgrade from any earlier version, with no modules refresh needed. Get it: https://github.com/theoretic/StaticPages (MIT licence; the changelog is in the repo) Feedback, bug reports and nginx rules from nginx folks are very welcome! 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now