Improve performance on poor connections: local assets, gzip, caching
- Replace Tailwind CDN (~350KB) with purged local CSS (~22KB) - Replace htmx unpkg CDN with local static file - Add Gzip middleware (standard library, sync.Pool) for all responses - Add Cache-Control: public, max-age=3600 for /static/* assets - Reduce status polling interval from 5s to 30s - Add scripts/build-css.sh for CSS regeneration after template changes - Document in bible-local/operations.md and history.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,37 @@
|
||||
|
||||
---
|
||||
|
||||
## 2026-03-14: Performance improvements for poor network connections
|
||||
|
||||
### Decision
|
||||
|
||||
Replaced external CDN dependencies with locally-served assets and added server-side compression
|
||||
to improve load times on poor or high-latency connections.
|
||||
|
||||
### What changed
|
||||
|
||||
- **Tailwind CSS**: replaced `cdn.tailwindcss.com` JIT runtime (~350KB) with a purged and minified
|
||||
local CSS file `web/static/tailwind.min.css` (~22KB). Generated via `tailwindcss` CLI scanning
|
||||
all templates. `package.json`, `tailwind.config.js`, `tw-input.css`, and `scripts/build-css.sh`
|
||||
added for CSS regeneration. `node_modules/` excluded from git.
|
||||
- **htmx**: replaced unpkg CDN with locally-served `web/static/js/htmx.min.js` (~47KB).
|
||||
- **Gzip middleware**: added `internal/middleware/gzip.go` — compresses all responses using
|
||||
standard library `compress/gzip`. Uses a sync.Pool to reuse writers. Registered first in the
|
||||
middleware chain in `cmd/pfs/main.go`.
|
||||
- **Cache-Control**: added `internal/middleware/static_cache.go` — sets
|
||||
`Cache-Control: public, max-age=3600` for all `/static/*` requests so browsers reuse
|
||||
CSS/JS across navigations without re-downloading.
|
||||
- **Polling interval**: `base.html` status polling reduced from 5 s to 30 s to cut background
|
||||
network traffic.
|
||||
|
||||
### Consequences
|
||||
|
||||
- When adding new Tailwind classes to templates, run `scripts/build-css.sh` to regenerate CSS.
|
||||
- First page load now requires no external network requests.
|
||||
- Binary size increases by ~70KB (embedded static assets).
|
||||
|
||||
---
|
||||
|
||||
## 2026-03-07: Embedded Scheduler with MariaDB Advisory Locks
|
||||
|
||||
### Decision
|
||||
|
||||
@@ -163,6 +163,42 @@ xattr -d com.apple.quarantine /path/to/pfs-darwin-arm64
|
||||
|
||||
---
|
||||
|
||||
## Frontend Assets (Tailwind CSS)
|
||||
|
||||
Static assets are embedded into the binary from `web/static/`. CSS and JS are served locally —
|
||||
no external CDN requests at runtime.
|
||||
|
||||
### Regenerate Tailwind CSS
|
||||
|
||||
Run this after adding new Tailwind utility classes to any HTML template:
|
||||
|
||||
```bash
|
||||
scripts/build-css.sh
|
||||
# or directly:
|
||||
node_modules/.bin/tailwindcss -i tw-input.css -o web/static/tailwind.min.css --minify
|
||||
```
|
||||
|
||||
First-time setup (requires Node.js):
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
`node_modules/` is excluded from git. `web/static/tailwind.min.css` **is** committed —
|
||||
rebuilding is only needed when templates change.
|
||||
|
||||
### Files involved
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| `tailwind.config.js` | Content paths for class scanning |
|
||||
| `tw-input.css` | Tailwind input (base/components/utilities directives) |
|
||||
| `web/static/tailwind.min.css` | Generated output — committed, embedded into binary |
|
||||
| `web/static/js/htmx.min.js` | htmx — committed, embedded into binary |
|
||||
| `scripts/build-css.sh` | Shortcut to regenerate CSS |
|
||||
|
||||
---
|
||||
|
||||
## Requirements
|
||||
|
||||
- Go 1.22+
|
||||
|
||||
Reference in New Issue
Block a user