Skip to content

Improve load performance with lazy loading and code splitting #374

Description

@ApparentlyPlus

Problem

The app currently suffers in JS load performance due to all page components and libraries being bundled into a single, large (1.2MB) file. This bundle is loaded upfront, even though users typically interact with only a subset of routes. As a result, time to interactive is massively increased (over 250ms average), and we have much slower initial load times, especially on mobile or slow connections.

Current impact

  • The routing setup loads page modules centrally, which couples route config with direct page imports.
  • The build output shows large application payloads that can be better split for caching and incremental loading.
  • Users may download code for pages they never visit, leading to a visibly worse experience on low end devices or slow internet connections.

Proposed solution

  • Introduce route level lazy loading for page components using dynamic imports.
  • Move route config to page identifiers plus optional props, and resolve components at runtime.
  • Add explicit manual chunking for JS dependencies in Vite config to improve cache performance and reduce main bundle pressure.

Other Remarks

Currently, even when running npm run build, Vite warns us about this:

> studentsapp@0.1.0 build
> vite build

vite v6.3.4 building for production...
✓ 1593 modules transformed.
dist/index.html                               3.46 kB │ gzip:   1.76 kB
dist/assets/uom_register-BaSQsMCX.md          5.54 kB
dist/assets/Syne-Regular-Pp1ONHiy.woff2      25.68 kB
dist/assets/Syne-Medium-BnbXqljD.woff2       27.17 kB
dist/assets/Syne-Bold-DAtoRcVV.woff2         27.20 kB
dist/assets/Syne-SemiBold-BHaLdpLo.woff2     27.37 kB
dist/assets/myUOMLogo-oyTF4fmj.png          237.41 kB
dist/assets/index-CbX1vU1G.css                1.99 kB │ gzip:   0.80 kB
dist/assets/index-2DgHfQef.js             1,277.73 kB │ gzip: 406.16 kB

(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions