Skip to content

Optimize frontend bundle with vendor chunking and lazy loading - #749

Merged
Tim020 merged 1 commit into
devfrom
feat/optimize-frontend-bundle
Dec 1, 2025
Merged

Optimize frontend bundle with vendor chunking and lazy loading#749
Tim020 merged 1 commit into
devfrom
feat/optimize-frontend-bundle

Conversation

@Tim020

@Tim020 Tim020 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR optimizes the frontend build by implementing vendor chunking and lazy-loading strategies to significantly reduce initial bundle size and improve loading performance.

Changes Made

  1. Manual Vendor Chunking (vite.config.js)

    • Implemented function-based manualChunks configuration
    • Split dependencies into logical chunks:
      • bootstrap-vendor: Bootstrap + Bootstrap-Vue (~1MB)
      • vue-vendor: Vue ecosystem (115KB)
      • utils-vendor: Utilities like lodash (80KB)
      • websocket-vendor: WebSocket library (6KB)
      • vendor: Other dependencies including jQuery/vuelidate (201KB)
    • Uses CommonJS-safe approach to avoid watch mode errors
  2. Lazy-Loaded Routes (src/router/index.js)

    • Changed HomeView from eager import to dynamic import
    • Enables on-demand loading of route components

Performance Impact

Before:

  • Single monolithic bundle: 1,419 KB (364 KB gzipped)

After:

  • Main app bundle: 64 KB (13.76 KB gzipped) - 95% reduction
  • Vendor chunks loaded separately and cached independently
  • Faster initial page load
  • Better long-term caching (vendor updates don't invalidate app code)

Build Compatibility

  • ✅ Works in production mode (npm run build)
  • ✅ Works in watch mode (npm run build -- --watch --mode=development)
  • ✅ No CommonJS entry point errors

Test Plan

  • Run npm run build - completes successfully
  • Run npm run build -- --watch --mode=development - no errors
  • Verify chunk sizes are as expected
  • Test application loads correctly in browser
  • Test all routes load properly with lazy imports
  • Verify vendor caching works across deployments

Future Optimization

This PR implements the "quick wins" for bundle optimization. A follow-up PR will explore Bootstrap-Vue tree-shaking to further reduce the bootstrap-vendor chunk by 30-50%.

🤖 Generated with Claude Code

…loading

- Add function-based manual vendor chunking to split dependencies:
  * bootstrap-vendor: Bootstrap + Bootstrap-Vue (~1MB)
  * vue-vendor: Vue ecosystem (115KB)
  * utils-vendor: Utilities like lodash (80KB)
  * websocket-vendor: WebSocket library (6KB)
  * vendor: Other dependencies including jQuery/vuelidate (201KB)
- Lazy-load HomeView component instead of eager import
- Use CommonJS-safe chunking strategy to avoid watch mode errors

Benefits:
- Main app bundle reduced from 1,419KB to 64KB (95% reduction)
- Better browser caching through vendor separation
- Faster initial page load with lazy-loaded routes
- Parallel chunk downloads for improved performance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added small-diff Small pull request client Pull requests changing front end code labels Dec 1, 2025
@github-actions

github-actions Bot commented Dec 1, 2025

Copy link
Copy Markdown

Test Results

31 tests  ±0   31 ✅ ±0   8s ⏱️ ±0s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 228efac. ± Comparison against base commit 2f3265a.

@Tim020
Tim020 merged commit d9c98ae into dev Dec 1, 2025
12 checks passed
@Tim020
Tim020 deleted the feat/optimize-frontend-bundle branch December 1, 2025 23:08
Tim020 added a commit that referenced this pull request Dec 1, 2025
- Create tree-shakeable plugin file importing only used components
- Replace global BootstrapVue and IconsPlugin imports with selective imports
- Import 50+ Bootstrap-Vue components and 8 icons actually used in codebase
- Maintain $bvModal plugin for modal operations

Components included:
- Layout & Grid: BContainer, BRow, BCol
- Forms: BForm, BFormGroup, BFormInput, BFormSelect, BFormCheckbox, etc.
- Buttons: BButton, BButtonGroup
- Table: BTable, BTableSimple, BTbody, BTr, BTh, BTd
- Navigation: BNavbar, BNavItem, BNavItemDropdown
- Tabs: BTabs, BTab
- Modals: BModal with $bvModal plugin
- Other: BAlert, BPagination, BProgress, BSpinner, BOverlay, etc.

Icons included:
- BIconPlusSquareFill, BIconCheckSquareFill, BIconXSquareFill
- BIconXCircle, BIconSquareFill, BIconQuestionCircleFill
- BIconClipboard, BIconCheckCircle

Benefits:
- Main bundle reduced from 1,419KB to 633KB (55% reduction)
- Gzipped size reduced from 364KB to 186KB (49% reduction)
- When combined with vendor chunking (PR #749), bootstrap-vendor
  chunk will be 266KB (67KB gzipped) vs 1,164KB (288KB gzipped)
- Overall 77% reduction in Bootstrap-Vue bundle size
- Maintains full compatibility with existing code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Pull requests changing front end code small-diff Small pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant