Improve speed

This commit is contained in:
Kevin
2026-05-22 11:15:22 +08:00
parent 87b6a7b804
commit 941c71e991
14 changed files with 132 additions and 49 deletions

View File

@@ -88,6 +88,12 @@ class DemoHandler(SimpleHTTPRequestHandler):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, directory=str(SCRIPT_DIR), **kwargs)
def end_headers(self) -> None:
path = self.path.split("?", 1)[0]
if path == "/labels.json" or path.endswith((".html", ".js", ".css")):
self.send_header("Cache-Control", "no-store")
super().end_headers()
def do_GET(self) -> None: # noqa: N802 (stdlib override)
if self.path.split("?", 1)[0] == "/labels.json":
self._send_labels()
@@ -99,7 +105,6 @@ class DemoHandler(SimpleHTTPRequestHandler):
self.send_response(HTTPStatus.OK)
self.send_header("Content-Type", "application/json; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.send_header("Cache-Control", "no-store")
self.end_headers()
self.wfile.write(body)