kjs-chunks icon indicating copy to clipboard operation
kjs-chunks copied to clipboard

Code splitting for Kotlin/JS browser apps

Code splitting for Kotlin/JS browser apps

This is a rough proof-of-concept that a Kotlin/JS browser app can be split into multiple chunks that can depend on each other dynamically. For example a Kotlin React app could be split into multiple smaller JS files that way.

Architecture

Modules

Configuration

Known limitations

  • Only works with the JS IR compiler.
  • The setup is fragile and can break with subsequent Kotlin updates.
  • Dynamic imports have unstable names (like kotlin_kjs_chunks_dynamic in this example).
  • @EagerInitialization must be used as a workaround to execute logic when loading a module, e.g. the index.