Skip to content

fix: S3 static deployment readiness (forms, error page, script loading)#3

Open
borice1984 wants to merge 1 commit into
wilwaldon:mainfrom
borice1984:fix/s3-deployment-readiness
Open

fix: S3 static deployment readiness (forms, error page, script loading)#3
borice1984 wants to merge 1 commit into
wilwaldon:mainfrom
borice1984:fix/s3-deployment-readiness

Conversation

@borice1984

Copy link
Copy Markdown

What

Three improvements that make the static template production-ready on S3 (or any static host):

  1. Formspree form submission — replaces mailto-only with a proper fetch-based POST
  2. error.html — new file required by S3 for non-404 error routing
  3. defer on non-module scripts — eliminates render-blocking

Why

Form submission

The previous implementation submitted the contact form by navigating window.location.href to a mailto: URL. On most desktop browsers this opens the local mail client rather than submitting over the network — it doesn't work for users without a mail client configured, and it provides no reliable delivery or tracking.

The updated forms.js checks for a data-formspree-endpoint attribute on the form element. If present, it POSTs via fetch() to that endpoint (Formspree or any compatible service). If absent, it falls back to the existing mailto: behavior so nothing breaks for setups that don't configure an endpoint.

To enable: sign up at https://formspree.io, create a form, and set the endpoint on your form:

<form data-contact-form data-formspree-endpoint="https://formspree.io/f/YOUR_ID">

The data-formspree-endpoint="" placeholder is already added to contact.html.

error.html

S3 static website hosting has two distinct error document settings: one for 404 and one for all other errors (access denied, server errors, etc.). Without a separate error.html, S3 serves a bare XML error response for non-404 errors. The new file matches the style of 404.html.

Script defer

bleeding-edge.js and heroImages.js are loaded with plain <script src> tags, which block HTML parsing until the scripts download and execute. Adding defer makes them execute after the document is parsed, consistent with how <script type="module"> already behaves.

Files changed

  • templates/static/base/js/forms.js — Formspree fetch support + UX fix
  • templates/static/base/contact.html — data-formspree-endpoint placeholder + defer
  • templates/static/base/index.html — defer on scripts
  • templates/static/base/page-2.html — defer on scripts
  • templates/static/base/page-3.html — defer on scripts
  • templates/static/base/page-4.html — defer on scripts
  • templates/static/base/404.html — defer on scripts
  • templates/static/base/error.html — new file

- forms.js: add Formspree fetch support as primary submit path; mailto:
  remains as fallback. Set data-formspree-endpoint on the form to enable.
  Also fixes a UX bug where success state was shown after location.href
  redirect in the fetch path.
- contact.html: add data-formspree-endpoint placeholder to form element
- All pages: add defer to non-module script tags to prevent render-blocking
- Add error.html for S3 error document routing (S3 requires a separate
  error document distinct from 404.html for access-denied / server errors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant