Diagnosing Blank Pages and Infinite Loading in Streamlit Apps
Solve the 'blank page' or 'infinite loading' issue in Streamlit. This guide diagnoses WebSocket failures, blocking computations, and cache conflicts with a step-by-step resolution path.
18 Sept 2025, 00:04 UTC

The Symptom: Server is Live, Page is Blank
A common frustration in Streamlit development is the "Ghost App": your terminal shows You can now view your Streamlit app in your browser, but the browser displays a blank white screen or a loading spinner that never disappears. This indicates that while the Python backend is running, the communication channel between the server and the frontend is broken or blocked.
Rapid Diagnostic Table
| Observation | Likely Cause | Primary Tool for Verification |
|---|---|---|
| Browser Console shows "WebSocket connection failed" | Proxy/Firewall blocking WebSockets | Browser DevTools (F12) > Console |
| App loads in Incognito but not in standard window | Cached JavaScript/Asset mismatch | Private Browsing Mode |
| Terminal shows no activity; CPU spikes to 100% | Blocking computation in main script | System Monitor / Task Manager |
| App hangs only in Docker/Remote SSH environments | Headless config or CORS mismatch | .streamlit/config.toml |
Step-by-Step Resolution Path
1. Validate the Network Bridge (WebSockets)
Streamlit relies on WebSockets for real-time bidirectional communication. If you are running your app behind a reverse proxy (like Nginx) or a corporate firewall, the HTTP request may succeed, but the WebSocket upgrade will fail, leaving the page blank.
- Check: Open Browser DevTools (F12), go to the Console tab, and look for
WebSocket connection to 'ws://...' failed. - Fix: Ensure your proxy allows the
UpgradeandConnectionheaders. If you are in a restricted network, try adjusting your.streamlit/config.tomlfile:
[server]
# Use with caution: disabling these can expose apps to CSRF attacks
enableCORS = false
enableXsrfProtection = false
Risk: Disabling CORS and XSRF protection should only be done in trusted internal networks. On public-facing apps, configure your proxy to handle the headers rather than disabling security in the app.
2. Rule Out Client-Side Asset Corruption
When updating Streamlit versions or deploying new builds, the browser may attempt to use cached JavaScript files that are incompatible with the current server version.
- Check: Open the app in an Incognito/Private window. If the app loads immediately, the issue is local cache.
- Fix: Perform a hard refresh (
Ctrl + F5orCmd + Shift + R) or clear the site data in the browser's Application tab.
3. Identify Blocking Main-Thread Operations
Streamlit executes the script from top to bottom on every interaction. If you have a heavy data-loading function or an infinite loop at the top level of your script, the server will never send the initial "Ready" signal to the frontend.
- Check: Check your terminal logs. If the app is stuck before the first
st.writeorst.titlecall, and your CPU is pinned, you have a blocking operation. - Fix: Wrap expensive data loading in
st.cache_datato ensure it only runs once.
import streamlit as st
import pandas as pd
import time
@st.cache_data
def load_massive_dataset():
# Simulate a 10-second load that would block the initial render
time.sleep(10)
return pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})
# This will now only block the first user, and only once
df = load_massive_dataset()
st.write("App Loaded Successfully!")
st.dataframe(df)
4. Correct Headless Environment Configuration
In remote environments (SSH, Docker, Cloud VMs), Streamlit may attempt to trigger a browser window open command that fails silently or hangs the process.
- Check: Check if the app works when run with the
--server.headless trueflag. - Fix: Explicitly set the headless mode in your startup command:
# Run this in your terminal/shell
streamlit run your_app.py --server.headless true
Verification and Rollback
To verify the fix, restart the Streamlit server and monitor the Network tab in DevTools. You should see a 101 Switching Protocols response for the WebSocket connection.
Rollback: If changes to .streamlit/config.toml cause unexpected behavior or security warnings, delete the file or comment out the enableCORS and enableXsrfProtection lines to return to default secure settings.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.