Password-protect a static page without a server
An Eleventy plugin that encrypts pages at build time and unlocks them in the browser — so confidential case studies can live on a fully static host.
Some of my case studies are covered by NDAs, but I still want them on this site — same type, same theme, same hosting — without standing up a server just to ask for a password. Static hosts are great at shipping HTML. They are not great at keeping secrets.
So I wrote an Eleventy plugin that encrypts a page at build time and leaves a small unlock screen in its place. The real markup never ships as plain HTML. The browser only sees it after someone enters the password.
Why not “just host it”
On a static host, a password gate usually means a serverless function, a third-party auth product, or hiding the URL and hoping. I wanted something simpler: build the page as usual, encrypt the HTML before the build finishes, and publish an unlock screen in its place. Anyone can fetch the file. Only the password opens it. No session, no user database — useful for portfolio work, not a substitute for real auth.
Hooked into the Eleventy build
The plugin registers as a normal Eleventy plugin, then rides the transform hook — the step that runs after a template has already been rendered to HTML. Authoring stays boring. Wire it once in the config, and opt a page in with a marker:
const staticrypt = require('./src/_plugins/staticrypt.js');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(staticrypt);
};
<!--PROTECT-->
Case studies stay Markdown or Nunjucks. Front matter, images, and layout stay the same. At build time the transform looks for that comment. No marker, and the page ships untouched. With the marker, it strips the comment, encrypts the finished HTML with a modern authenticated cipher, writes the encrypted payload beside the page as JSON, and replaces the public output with a lightweight unlock screen — same site CSS, a password field, remember-me. View source hits a wall, not a draft.
One gotcha worth keeping in mind: if detection is a blunt “does this HTML contain the marker,” a docs page that shows <!--PROTECT--> in a code sample can encrypt itself. Treat examples of the marker as a real consideration when you write about the plugin — not only when you protect a case study.
Markdown / template
→ Eleventy renders HTML
→ transform sees
→ encrypt page → payload JSON
→ public HTML = unlock screen
→ visitor enters password
→ browser unlocks → real page
What happens in the browser
Visit a protected URL and you get the unlock screen first. Submit the password and the client derives a key, opens the payload, and swaps the gate for the real document — head assets, body markup, and the scripts the page needs to behave like the rest of the site.
A few product details mattered more than the happy path:
Remember me, with an expiry. Right now this site uses one shared password across protected pages. Remembering a successful unlock in localStorage for a few days means you are not re-entering it on every case study during a walkthrough — then it expires. Long enough for a conversation. Short enough that a shared machine does not stay open forever. Per-page or per-visitor passwords would be a different product.
Keep the theme intact. This site’s hue and light/dark mode live in the same storage space. A naive unlock that stomps localStorage or rebuilds the document carelessly would flash the wrong theme. The unlock flow preserves theme state and re-initializes the controls after the real page lands.
Reload behavior after swap. Decrypting into a live document is not the same as a normal navigation. Scripts that expected a full page load need a second chance. The plugin accounts for that so decrypted pages still get theme controls, view transitions, and the other progressive bits the rest of the site uses.
Fail closed in the UI. Wrong password stays on the gate with an error. There is no partial render of “almost decrypted” content.
How I use it here
Protected case studies carry the marker. The public work index can still list them. The overview can still link them. The lock icon on those titles is not theater — the destination stays encrypted until I share a password.
That split is the point of a static portfolio with confidential work. The index stays open. The evidence stays closed. I do not need a CMS permission model to get that shape.
What this is, and what it is not
In plain terms: Eleventy finishes rendering the page, the plugin encrypts that HTML during the build, and the public URL ships an unlock screen instead of the article. Unlocking happens entirely in the visitor’s browser. No server round-trip, no account system — just a password I share one-to-one when I want someone to see the work. The plugin is open source so other Eleventy folks can adapt the pattern: jasonquintin/11ty-Password-Protect.
It is not a substitute for keeping truly sensitive files off the public internet. Anyone who has the password can open the page. Anyone who can fetch the site can fetch the encrypted payload. The password is the secret. I hand it out the same way I hand out the work — deliberately, to people I am already talking to.
If you need per-user accounts, audit logs, or the ability to revoke access instantly, use a real auth layer. If you need a password-protected case study on a static host that still looks like the rest of your site after it opens, a build transform and a small unlock screen will get you there.