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
This commit is contained in:
10
.replit
10
.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
|
||||
|
||||
18
serve.py
Normal file
18
serve.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user