If hosting on Cloudflare Pages is acceptable, the cloudflare-pages-auth github repo contains instructions on how to set up the cloudflare actions to block access to the site via middleware functions.
Hosting Setup:
- Create a
CFP_PASSWORDenvironment variable on the build platform containing the password you would like to use.
Advantages
- Unlike using Staticrypt,
enableSPAcan be left enabled (true), resulting in a smoother browsing experience.
Limitations
- This method only works on the Cloudflare Pages platform.