Files
web-portfolio/serve.py
Replit Agent 82d7040aa3 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
2026-07-04 21:54:47 +00:00

19 lines
583 B
Python

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()