Skip to content

Lazy load rarely used pages#338

Closed
mugnivenko wants to merge 2 commits into
hplush:mainfrom
mugnivenko:chore/bundle-split
Closed

Lazy load rarely used pages#338
mugnivenko wants to merge 2 commits into
hplush:mainfrom
mugnivenko:chore/bundle-split

Conversation

@mugnivenko
Copy link
Copy Markdown

Fixes #38

I added lazy loading of the about, export, and import pages.

Motivation

To make the size of the loading JS smaller.

Comment thread web/main/main.svelte Outdated
<FeedByCategoriesPage page={$currentPage} />
{:else if $currentPage.route === 'about'}
<AboutPage page={$currentPage} />
{#await import('../pages/about.svelte') then {default: AboutPage}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we forgot about some loader during the page loading.

Comment thread web/main/main.svelte Outdated
@@ -88,9 +87,13 @@
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As I mention in the issue it is better strategy to join pages in the bundles according to user behavior.

I think we can bundle all settings (expect import and export) into the single bundle.

Comment thread web/.size-limit.json Outdated
"!dist/assets/playpen-sans-*.woff2",
"!dist/assets/*-{italic,math,latin-ext}-*.woff2"
"!dist/assets/*-{italic,math,latin-ext}-*.woff2",
"!dist/assets/{export,import,about}-*.js"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe by moving to custom bundles we can add some custom prefix?

Comment thread web/.size-limit.json
"name": "Core scripts to execute",
"path": "dist/assets/index-*.js",
"brotli": false,
"limit": "310 KB"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let’s update core scripts.

But as I see button-* and core-* was moved out. Do we need this bundle to show home page? If yes, we need to update Core scripts to execute metrics (and it is better to have some automation to avoid manually picking bundles).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've updated the script according to the chunks

image

@@ -0,0 +1,15 @@
<script lang="ts">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pages folder is not beautiful page right now. JS bundle splitting is a simple feature which we should not think about, it should not force us to change architecture and project stricture.

Comment thread web/main/main.svelte
<AboutPage page={$currentPage} />
{:else if $currentPage.route === 'cloud'}
<CloudPage page={$currentPage} />
{:else if $currentPage.route === 'about' || $currentPage.route === 'interface' || $currentPage.route === 'cloud'}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

3 pages moved to JS chunk is still almost nothing. We need solid and finished solution for all pages.

You need to think about good strategy first, do not rush.

@mugnivenko
Copy link
Copy Markdown
Author

I have thought about how to keep the feature out of developers’ concerns and make it work automatically, but I couldn’t come up with a solution. Either we need to somehow combine pages into the desired chunks in the code or make all pages async and combine them into chunks via Vite’s manualChunks option. Both solutions require developers to think about code splitting every time they add a new page. I’m out of options in my understanding of the problem. Can you please give possible directions to explore for new solutions?

@ai
Copy link
Copy Markdown
Contributor

ai commented May 31, 2026

The whole task is about finding the right way to implement. Let’s move task back to waiting list (maybe new API will be introduced)

@ai ai closed this May 31, 2026
@mugnivenko
Copy link
Copy Markdown
Author

To introduce the new API I need clearer requirements about what the final result should look like. The requirements now quite contradict each other.

We should not touch the project structure and think about splitting.

As we do not use a framework that gets the work done for us, we should at least think about code splitting in the main.svelte file.
The desire to combine some pages into one loadable chunk makes us somehow introduce this requirement in the code.
As a possible solution, I may suggest writing a Vite plugin. The plugin will automatically add lazy loading for all pages and will use a custom config that defines which pages to combine. The solution might be overkill for this case, but it at least covers all requirements.

@ai
Copy link
Copy Markdown
Contributor

ai commented Jun 1, 2026

I told about Vite API.

@mugnivenko
Copy link
Copy Markdown
Author

Could you please point me to where you mentioned the Vite API? I couldn’t find it. Also, do you consider this solution suitable?

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.

Split JS bundle

2 participants