fix: prevent CDN from caching 404 responses for static assets
- add_no_cache_headers now only applies long-cache headers to 2xx responses - non-2xx static responses (e.g. 404) get no-cache to prevent CDN from caching error pages (which was the root cause of office.hyacinth.im failing to load - Cloudflare cached a 404 for phaser.js for 2.7 days) - add version cache-bust param to phaser.js script tag (matching all other static assets)
This commit is contained in:
1 parent
53d33d6cdf
commit
878793d74b
2 files changed
+6
-5
No files matched your search
+3
-2
@@ -109,10 +109,11 @@ def _require_asset_editor_auth():
|
||||
def add_no_cache_headers(response):
|
||||
"""Apply cache policy by path:
|
||||
- HTML/API/state: no-cache (always fresh)
|
||||
- /static assets: long cache (filenames are versioned with ?v=VERSION_TIMESTAMP)
|
||||
- /static assets (2xx only): long cache (filenames are versioned with ?v=VERSION_TIMESTAMP)
|
||||
- /static assets (non-2xx, e.g. 404): no-cache to prevent CDN from caching errors
|
||||
"""
|
||||
path = (request.path or "")
|
||||
if path.startswith('/static/'):
|
||||
if path.startswith('/static/') and 200 <= response.status_code < 300:
|
||||
response.headers["Cache-Control"] = "public, max-age=31536000, immutable"
|
||||
response.headers.pop("Pragma", None)
|
||||
response.headers.pop("Expires", None)
|
||||
|
||||
+3
-3
@@ -1259,7 +1259,7 @@
|
||||
<button id="lang-btn-cn" onclick="setUILanguage('zh')" style="padding:8px 10px; font-family:ArkPixel,monospace; font-size:13px; cursor:pointer; border:2px solid #333; border-radius:5px; background:#333; color:#fff;">CN</button>
|
||||
</div>
|
||||
|
||||
<script src="/static/vendor/phaser-3.80.1.min.js"></script>
|
||||
<script src="/static/vendor/phaser-3.80.1.min.js?v={{VERSION_TIMESTAMP}}"></script>
|
||||
<script>
|
||||
// 简易中英文切换
|
||||
let uiLang = localStorage.getItem('uiLang') || 'en';
|
||||
@@ -4605,8 +4605,8 @@ function toggleBrokerPanel() {
|
||||
typewriterText = '';
|
||||
typewriterIndex = 0;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('fetchStatus apply error', err);
|
||||
typewriterTarget = '状态更新异常,正在恢复...';
|
||||
typewriterText = '';
|
||||
|
||||
Reference in new issue
Block a user