We are building a JS SDK using KMP/JS. The bundle ...
# javascript
m
We are building a JS SDK using KMP/JS. The bundle size gets too heavy(total size ~4+ MB) which impacts our first page load time on WEB. We are using below dependencies
Copy code
sourceSets {
    val commonMain by getting {
      dependencies {
        implementation(libs.bundles.common.ktor)
        implementation(libs.coroutines.core)
        implementation(libs.touchlab.kermit)
        implementation(libs.arrow.core)
        implementation(libs.kotlinx.datetime)
        implementation(libs.bundles.multiplatformSettings)
        kotlin.srcDir(buildConfigGenerator.map { it.destinationDir })
      }
    }
    val commonTest by getting {
      dependencies {
        implementation(libs.bundles.common.test)
      }
    }
    val jsMain by getting {
      dependencies {
        implementation(npm("uuid", libs.versions.uuid.get()))
        implementation(libs.ktor.client.js)
      }
    }
Is there any scope for reducing the bundle size ?
r
You can drop Ktor and implement your own http client with fetch api. See also https://youtrack.jetbrains.com/issue/KTOR-1084
1
gratitude thank you 1
👍 1
e
One thing you should definitely do is set Webpack to output a statistics file. You can then analyze and figure out which dependency is adding the biggest chunk of size.
gratitude thank you 1
Don't mess with dependencies before analyzing the bundle.
@Robert Jaros damn, I knew that Ktor added quite a bit of size, but the data in the issue is quite shocking. It's basically not even worth using Ktor when targeting JS.