feat: cache-header für pwa-dateien
- index.html, sw.js und Manifest mit no-cache, damit Updates ankommen - gehashte Assets mit max-age=31536000, immutable; Icons einen Tag - Manifest mit Content-Type application/manifest+json Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0ad6d248cf
commit
9cf163c295
2 files changed
+59
-2
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def built(static_dir):
|
||||
"""Minimal stand-in for the frontend build output."""
|
||||
(static_dir / "assets").mkdir()
|
||||
(static_dir / "icons").mkdir()
|
||||
(static_dir / "index.html").write_text("<html>spa</html>")
|
||||
(static_dir / "sw.js").write_text("self.addEventListener('fetch', () => {})")
|
||||
(static_dir / "workbox-abc123.js").write_text("// workbox")
|
||||
(static_dir / "manifest.webmanifest").write_text('{"name": "LAN-Clipboard"}')
|
||||
(static_dir / "assets" / "index-abc123.js").write_text("console.log(1)")
|
||||
(static_dir / "icons" / "icon-192.png").write_bytes(b"\\x89PNG")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["/", "/clips/1", "/index.html", "/sw.js"])
|
||||
def test_entry_points_are_revalidated(built, client, path):
|
||||
assert client.get(path).headers["cache-control"] == "no-cache"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["/assets/index-abc123.js", "/workbox-abc123.js"])
|
||||
def test_hashed_files_are_immutable(built, client, path):
|
||||
assert client.get(path).headers["cache-control"] == "public, max-age=31536000, immutable"
|
||||
|
||||
|
||||
def test_icons_are_cached_for_a_day(built, client):
|
||||
assert client.get("/icons/icon-192.png").headers["cache-control"] == "public, max-age=86400"
|
||||
|
||||
|
||||
def test_manifest_content_type(built, client):
|
||||
response = client.get("/manifest.webmanifest")
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"].startswith("application/manifest+json")
|
||||
assert response.headers["cache-control"] == "no-cache"
|
||||
|
||||
|
||||
def test_service_worker_is_javascript(built, client):
|
||||
assert "javascript" in client.get("/sw.js").headers["content-type"]
|
||||
Reference in new issue
Block a user