Spaces:
Sleeping
chore: production polish — minify served JS/CSS + proper meta (de-"vibecoded")
Browse filesRemoves the dev-tools tells without touching the (commented) source:
- server.py: /static/<*.js|*.css> is now minified on the fly (rjsmin/rcssmin,
cached by mtime, long cache headers) — app.js 405→256KB, app.css 202→129KB,
comment-free. Source stays the single truth; any minify failure falls back to
the raw file. Added rjsmin/rcssmin to requirements.
- index.html: meta description, theme-color, color-scheme, referrer policy,
and noindex on the raw engine URL (canonical product is turingdna.com).
Console already clean (0 console.log). Minified output node-check-valid; app runs
on the raw-fallback path in preview with no console warnings. Cache-buster
-> v=20260608-min. Suite 285.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- dee/server.py +41 -0
- dee/static/index.html +8 -2
- requirements.txt +5 -0
|
@@ -58,6 +58,38 @@ from dee.optimizer.search import SearchConfig, apply_variant, evolve
|
|
| 58 |
logger = logging.getLogger("dee.server")
|
| 59 |
|
| 60 |
STATIC_DIR = Path(__file__).resolve().parent / "static"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
STATE_DIR = Path.home() / ".dee" / "state"
|
| 62 |
OUTPUT_DIR = Path.home() / ".dee" / "output"
|
| 63 |
DESKTOP_DIR = Path.home() / "Desktop"
|
|
@@ -679,6 +711,15 @@ def create_app() -> Flask:
|
|
| 679 |
|
| 680 |
@app.get("/static/<path:filename>")
|
| 681 |
def static_file(filename: str) -> Response:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
return send_from_directory(STATIC_DIR, filename)
|
| 683 |
|
| 684 |
# ─── /api/whoami — auth diagnostic ──────────────────────────────────
|
|
|
|
| 58 |
logger = logging.getLogger("dee.server")
|
| 59 |
|
| 60 |
STATIC_DIR = Path(__file__).resolve().parent / "static"
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# Production assets are minified on the fly (cached by mtime) so the served JS/CSS
|
| 64 |
+
# is compact + comment-free — source files stay the single source of truth.
|
| 65 |
+
# Conservative minifiers (rjsmin/rcssmin); any failure falls back to the raw file.
|
| 66 |
+
_MIN_CACHE: Dict[str, tuple] = {}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _minified_asset(filename: str) -> Optional[str]:
|
| 70 |
+
path = STATIC_DIR / filename
|
| 71 |
+
try:
|
| 72 |
+
mtime = path.stat().st_mtime
|
| 73 |
+
except OSError:
|
| 74 |
+
return None
|
| 75 |
+
ent = _MIN_CACHE.get(filename)
|
| 76 |
+
if ent and ent[0] == mtime:
|
| 77 |
+
return ent[1]
|
| 78 |
+
try:
|
| 79 |
+
src = path.read_text(encoding="utf-8")
|
| 80 |
+
if filename.endswith(".js"):
|
| 81 |
+
import rjsmin
|
| 82 |
+
out = rjsmin.jsmin(src)
|
| 83 |
+
else:
|
| 84 |
+
import rcssmin
|
| 85 |
+
out = rcssmin.cssmin(src)
|
| 86 |
+
_MIN_CACHE[filename] = (mtime, out)
|
| 87 |
+
return out
|
| 88 |
+
except Exception: # noqa: BLE001 — never let minification break asset serving
|
| 89 |
+
logger.exception("minify failed for %s; serving raw", filename)
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
|
| 93 |
STATE_DIR = Path.home() / ".dee" / "state"
|
| 94 |
OUTPUT_DIR = Path.home() / ".dee" / "output"
|
| 95 |
DESKTOP_DIR = Path.home() / "Desktop"
|
|
|
|
| 711 |
|
| 712 |
@app.get("/static/<path:filename>")
|
| 713 |
def static_file(filename: str) -> Response:
|
| 714 |
+
# Serve minified JS/CSS (cached) for a clean, compact production surface.
|
| 715 |
+
if "/" not in filename and filename.endswith((".js", ".css")):
|
| 716 |
+
body = _minified_asset(filename)
|
| 717 |
+
if body is not None:
|
| 718 |
+
mime = "application/javascript" if filename.endswith(".js") else "text/css"
|
| 719 |
+
resp = Response(body, mimetype=mime)
|
| 720 |
+
# safe to cache hard: every reference is query-string cache-busted (?v=)
|
| 721 |
+
resp.headers["Cache-Control"] = "public, max-age=31536000"
|
| 722 |
+
return resp
|
| 723 |
return send_from_directory(STATIC_DIR, filename)
|
| 724 |
|
| 725 |
# ─── /api/whoami — auth diagnostic ──────────────────────────────────
|
|
@@ -4,6 +4,12 @@
|
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
<title>TuringDNA · Engine</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
<!-- Theme bootstrap — runs BEFORE the stylesheet so <html data-theme> is
|
| 8 |
set before first paint (no flash on load). Dark is the default; a
|
| 9 |
saved choice (from the topbar toggle) overrides it. First-party
|
|
@@ -22,7 +28,7 @@
|
|
| 22 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 23 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 24 |
without them, users keep getting the stale file for up to a week. -->
|
| 25 |
-
<link rel="stylesheet" href="/static/app.css?v=20260608-
|
| 26 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 27 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 28 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
@@ -1811,6 +1817,6 @@
|
|
| 1811 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1812 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1813 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1814 |
-
<script src="/static/app.js?v=20260608-
|
| 1815 |
</body>
|
| 1816 |
</html>
|
|
|
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
<title>TuringDNA · Engine</title>
|
| 7 |
+
<meta name="description" content="TuringDNA — an integrated protein- and DNA-engineering workbench: directed evolution, CRISPR guide design, primer analysis, and a plasmid editor." />
|
| 8 |
+
<meta name="theme-color" content="#1b1a17" />
|
| 9 |
+
<meta name="color-scheme" content="dark light" />
|
| 10 |
+
<meta name="referrer" content="strict-origin-when-cross-origin" />
|
| 11 |
+
<!-- The canonical product lives at turingdna.com; the raw engine URL isn't indexed. -->
|
| 12 |
+
<meta name="robots" content="noindex,follow" />
|
| 13 |
<!-- Theme bootstrap — runs BEFORE the stylesheet so <html data-theme> is
|
| 14 |
set before first paint (no flash on load). Dark is the default; a
|
| 15 |
saved choice (from the topbar toggle) overrides it. First-party
|
|
|
|
| 28 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 29 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 30 |
without them, users keep getting the stale file for up to a week. -->
|
| 31 |
+
<link rel="stylesheet" href="/static/app.css?v=20260608-min" />
|
| 32 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 33 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 34 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
|
|
| 1817 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1818 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1819 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1820 |
+
<script src="/static/app.js?v=20260608-min" defer></script>
|
| 1821 |
</body>
|
| 1822 |
</html>
|
|
@@ -24,3 +24,8 @@ openpyxl>=3.1.0
|
|
| 24 |
# (with built-in caching). Adds ~6 MB to the image; worth it to keep
|
| 25 |
# auth working without rolling Supabase back to legacy keys.
|
| 26 |
PyJWT[crypto]>=2.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# (with built-in caching). Adds ~6 MB to the image; worth it to keep
|
| 25 |
# auth working without rolling Supabase back to legacy keys.
|
| 26 |
PyJWT[crypto]>=2.8.0
|
| 27 |
+
|
| 28 |
+
# Conservative JS/CSS minifiers — production assets are minified on the fly
|
| 29 |
+
# (dee/server.py:_minified_asset). Pure-Python, no build step.
|
| 30 |
+
rjsmin>=1.2.0
|
| 31 |
+
rcssmin>=1.1.0
|