Skip to content

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Jun 23, 2025

Title

fix: do not import css unless needed

Description

Dynamically import CSS and app.tsx JS file only when we need to render the UI instead of on every page load.

For content-addressed data requests (the whole point of the service worker gateway), we don't need to load the CSS or react JS.

Related #759

Notes & open questions

The current CSS file is ~90kb, and an extra network request is made for every page load (2 non-cached requests when hitting a subdomain directly). Removing this should help with the initial load time.

I’ve got CSS and js for react/ui code importing dynamically now and the initial bundle size has been reduced (after redirect-config bounce changes in #759) from 255kB to 39kB for the initial javascript.. and removes 90~kb of CSS on index.html page loads.

Basically this results in a significant first-load reduction from ~32s using 3g throttling to 19s in chrome. (using “finish” time in chrome dev tools.. i.e. from the time all the network requests started (hey, gimme the content of this URL) to redirect+style+content loading + rendering being done)

without the throttling, the reduction in loadtime is improved but almost insignificant. (load time 857ms, DOMContentLoaded 476ms) — not much difference from #759

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

SgtPooki added 30 commits June 17, 2025 14:02
@SgtPooki SgtPooki changed the base branch from main to fix/config-reload-page June 23, 2025 17:34
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review. tested locally and works fine.

no FOUC, but it's also technically a race condition ¯_(ツ)_/¯

@SgtPooki SgtPooki changed the title fix: do not import css unless needed fix: do not import css or react JS unless needed Jun 23, 2025
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review after adding dynamic JS loading and splitting react/ui JS out from initial page hits

@SgtPooki SgtPooki marked this pull request as ready for review June 23, 2025 19:08
Base automatically changed from fix/config-reload-page to main June 23, 2025 19:14
@SgtPooki SgtPooki merged commit 78d4d45 into main Jun 23, 2025
18 checks passed
@SgtPooki SgtPooki deleted the fix/config-reload-page-dynamic-css branch June 23, 2025 19:41
SgtPooki added a commit that referenced this pull request Jun 23, 2025
This reverts commit 78d4d45.

We need to open back up #773 and fix the UI when loading from cloudflare.
SgtPooki added a commit that referenced this pull request Jun 23, 2025
This reverts commit 78d4d45.

We need to open back up #773 and fix the UI when loading from cloudflare.
SgtPooki added a commit that referenced this pull request Jun 23, 2025
* Revert "fix: do not import css or react JS unless needed (#773)"

This reverts commit 78d4d45.

We need to open back up #773 and fix the UI when loading from cloudflare.

* fix: cloudflare redirect works
SgtPooki added a commit that referenced this pull request Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant