-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: add pre-built compression and code splitting for frontend assets #2705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 4 files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 4 files
Prompt for AI agents (all 1 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="backend/chainlit/server.py">
<violation number="1" location="backend/chainlit/server.py:283">
P2: `Accept-Encoding` quality values are ignored, so a client that explicitly disallows gzip/Brotli (q=0) will still receive that encoding. Parse the header and only serve a precompressed file when the requested encoding’s q-value is greater than 0.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
| if "br" in accept_encoding: | ||
| br_path = file_path.with_suffix(file_path.suffix + ".br") | ||
| if br_path.is_file(): | ||
| return FileResponse( | ||
| br_path, | ||
| media_type=content_type, | ||
| headers={"Content-Encoding": "br", "Vary": "Accept-Encoding"}, | ||
| ) | ||
|
|
||
| if "gzip" in accept_encoding: | ||
| gz_path = file_path.with_suffix(file_path.suffix + ".gz") | ||
| if gz_path.is_file(): | ||
| return FileResponse( | ||
| gz_path, | ||
| media_type=content_type, | ||
| headers={"Content-Encoding": "gzip", "Vary": "Accept-Encoding"}, | ||
| ) | ||
|
|
||
| return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Accept-Encoding quality values are ignored, so a client that explicitly disallows gzip/Brotli (q=0) will still receive that encoding. Parse the header and only serve a precompressed file when the requested encoding’s q-value is greater than 0.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/chainlit/server.py, line 283:
<comment>`Accept-Encoding` quality values are ignored, so a client that explicitly disallows gzip/Brotli (q=0) will still receive that encoding. Parse the header and only serve a precompressed file when the requested encoding’s q-value is greater than 0.</comment>
<file context>
@@ -275,37 +275,71 @@ async def serve_public_file(
+) -> Optional[FileResponse]:
+ content_type = mimetypes.guess_type(str(file_path))[0] or "application/octet-stream"
+
+ if "br" in accept_encoding:
+ br_path = file_path.with_suffix(file_path.suffix + ".br")
+ if br_path.is_file():
</file context>
| if "br" in accept_encoding: | |
| br_path = file_path.with_suffix(file_path.suffix + ".br") | |
| if br_path.is_file(): | |
| return FileResponse( | |
| br_path, | |
| media_type=content_type, | |
| headers={"Content-Encoding": "br", "Vary": "Accept-Encoding"}, | |
| ) | |
| if "gzip" in accept_encoding: | |
| gz_path = file_path.with_suffix(file_path.suffix + ".gz") | |
| if gz_path.is_file(): | |
| return FileResponse( | |
| gz_path, | |
| media_type=content_type, | |
| headers={"Content-Encoding": "gzip", "Vary": "Accept-Encoding"}, | |
| ) | |
| return None | |
| encodings: dict[str, float] = {} | |
| for value in accept_encoding.lower().split(","): | |
| token = value.strip() | |
| if not token: | |
| continue | |
| parts = token.split(";") | |
| encoding = parts[0] | |
| q = 1.0 | |
| for part in parts[1:]: | |
| if part.strip().startswith("q="): | |
| try: | |
| q = float(part.split("=", 1)[1]) | |
| except ValueError: | |
| q = 0.0 | |
| encodings[encoding] = q | |
| if encodings.get("br", 0) > 0: | |
| br_path = file_path.with_suffix(file_path.suffix + ".br") | |
| if br_path.is_file(): | |
| return FileResponse( | |
| br_path, | |
| media_type=content_type, | |
| headers={"Content-Encoding": "br", "Vary": "Accept-Encoding"}, | |
| ) | |
| if encodings.get("gzip", 0) > 0: | |
| gz_path = file_path.with_suffix(file_path.suffix + ".gz") | |
| if gz_path.is_file(): | |
| return FileResponse( | |
| gz_path, | |
| media_type=content_type, | |
| headers={"Content-Encoding": "gzip", "Vary": "Accept-Encoding"}, | |
| ) | |
| return None |
Description:
Addresses #2340
Initial load reduced from ~1.07MB to ~850KB (brotli).
Summary by cubic
Pre-built gzip and Brotli assets and vendor code splitting to reduce initial load and remove runtime compression overhead, addressing #2340. Initial load drops from ~1.07MB to ~850KB.
New Features
Dependencies
Written for commit 6f45e56. Summary will update automatically on new commits.