Skip to content

Conversation

@Sumeet213
Copy link

@Sumeet213 Sumeet213 commented Dec 1, 2025

Description:

Addresses #2340

  • Pre-build gzip and brotli compressed assets at build time
  • Serve pre-compressed files directly (no runtime CPU overhead)
  • Split vendor libraries into cacheable chunks

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

    • Backend serves .br/.gz files when supported (sets Content-Encoding and Vary).
    • Build-time compression via vite-plugin-compression for gzip and Brotli (keeps original files).
    • Manual code splitting for vendor chunks (react, UI, markdown, utils) to improve caching.
  • Dependencies

    • Added vite-plugin-compression ^0.5.1.

Written for commit 6f45e56. Summary will update automatically on new commits.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. frontend Pertains to the frontend. labels Dec 1, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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

Comment on lines +283 to +301
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
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 4, 2025

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(
+) -&gt; Optional[FileResponse]:
+    content_type = mimetypes.guess_type(str(file_path))[0] or &quot;application/octet-stream&quot;
+
+    if &quot;br&quot; in accept_encoding:
+        br_path = file_path.with_suffix(file_path.suffix + &quot;.br&quot;)
+        if br_path.is_file():
</file context>
Suggested change
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
Fix with Cubic

@github-actions
Copy link

This PR is stale because it has been open for 14 days with no activity.

@github-actions github-actions bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 19, 2025
@asvishnyakov
Copy link
Member

@github-actions Leave it for now, I'll review in a few days

@github-actions github-actions bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Pertains to the frontend. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants