From 82d7040aa39da8788fff46207dfd891e96ee6119 Mon Sep 17 00:00:00 2001 From: Replit Agent Date: Sat, 4 Jul 2026 21:54:47 +0000 Subject: [PATCH] Ensure website previews update instantly by disabling browser caching Create a custom server script to serve files with explicit no-cache headers, resolving issues where the preview iframe displayed stale content due to browser caching. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f5797e65-2210-4d2e-bf70-278d8a0098c1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 2ef8619a-6329-44ec-aa16-6d651c828315 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/2a2c58da-54a0-4c86-8ad0-3b93439f70de/f5797e65-2210-4d2e-bf70-278d8a0098c1/D15BHvH Replit-Helium-Checkpoint-Created: true --- .replit | 10 +++++----- serve.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 serve.py diff --git a/.replit b/.replit index 60cd8ed..6f175b6 100644 --- a/.replit +++ b/.replit @@ -16,14 +16,14 @@ args = "Start application" name = "Start application" author = "agent" -[[workflows.workflow.tasks]] -task = "shell.exec" -args = "python3 -m http.server 5000" -waitForPort = 5000 - [workflows.workflow.metadata] outputType = "webview" +[[workflows.workflow.tasks]] +task = "shell.exec" +args = "python3 serve.py" +waitForPort = 5000 + [[ports]] localPort = 5000 externalPort = 80 diff --git a/serve.py b/serve.py new file mode 100644 index 0000000..6e11caa --- /dev/null +++ b/serve.py @@ -0,0 +1,18 @@ +import http.server +import socketserver + +PORT = 5000 + +class NoCacheHandler(http.server.SimpleHTTPRequestHandler): + def end_headers(self): + self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') + self.send_header('Pragma', 'no-cache') + self.send_header('Expires', '0') + super().end_headers() + +class ReusableTCPServer(socketserver.TCPServer): + allow_reuse_address = True + +with ReusableTCPServer(("0.0.0.0", PORT), NoCacheHandler) as httpd: + print(f"Serving on port {PORT} with cache disabled") + httpd.serve_forever()