diff --git a/frontend/index.html b/frontend/index.html
index 24cea3f2770..c59c69bfe74 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -60,7 +60,6 @@
{{ title }}
-
diff --git a/marimo/_server/api/endpoints/assets.py b/marimo/_server/api/endpoints/assets.py
index 5df2bf81ddb..65296f4d348 100644
--- a/marimo/_server/api/endpoints/assets.py
+++ b/marimo/_server/api/endpoints/assets.py
@@ -4,7 +4,7 @@
import mimetypes
import os
import re
-from typing import TYPE_CHECKING, Optional
+from typing import TYPE_CHECKING
from starlette.authentication import requires
from starlette.exceptions import HTTPException
@@ -15,7 +15,6 @@
from marimo._config.manager import UserConfigManager
from marimo._runtime.virtual_file import EMPTY_VIRTUAL_FILE, read_virtual_file
from marimo._server.api.deps import AppState
-from marimo._server.file_router import MarimoFileKey
from marimo._server.router import APIRouter
from marimo._server.templates.templates import (
home_page_template,
@@ -91,25 +90,6 @@ async def index(request: Request) -> HTMLResponse:
return HTMLResponse(html)
-# This serves the custom.css file if it was
-# supplied in the app config
-@router.get("/custom.css")
-@requires("read")
-def custom_css(request: Request) -> Response:
- app_state = AppState(request)
- file_key: Optional[MarimoFileKey] = (
- app_state.query_params(FILE_QUERY_PARAM_KEY)
- or app_state.session_manager.file_router.get_unique_file_key()
- )
-
- if not file_key:
- return Response("", media_type="text/css")
-
- app_manager = app_state.session_manager.app_manager(file_key)
- css = app_manager.read_css_file() or ""
- return Response(css, media_type="text/css")
-
-
STATIC_FILES = [
r"(favicon\.ico)",
r"(circle-check\.ico)",
diff --git a/marimo/_server/templates/templates.py b/marimo/_server/templates/templates.py
index 17533cc8cef..7a0a144826d 100644
--- a/marimo/_server/templates/templates.py
+++ b/marimo/_server/templates/templates.py
@@ -65,6 +65,14 @@ def notebook_page_template(
"{{ mode }}",
"read" if mode == SessionMode.RUN else "edit",
)
+ # If has custom css, inline the css and add to the head
+ if app_config.css_file:
+ css_contents = read_css_file(app_config.css_file, filename=filename)
+ if css_contents:
+ css_contents = f""
+ # Append to head
+ html = html.replace("", f"{css_contents}")
+
return html
@@ -167,7 +175,7 @@ def static_notebook_template(
.replace('src="./', f'crossorigin="anonymous" src="{asset_url}/')
)
- # Append to body
+ # Append to head
html = html.replace("", f"{static_block}")
# Append to body
html = html.replace("