Is there anything I can do to reduce the size of t...
# javascript
d
Is there anything I can do to reduce the size of the built .js file for a Kotlin/React project? For a relatively simple project the js file is 2.7 MB. I am using the gradle
build
command, which I guess it’s already doing DCE (Dead Code Elimination).
t
There are 2 main blockers for webpack optimization: 1. No root export 2. No es module support Write please Kotlin version and mode (ir or legacy).
d
I am not sure where I should specify the Kotlin version in Gradle. I can’t see any Kotlin version written in my JS gradle file. I tried using both ir and legacy. With IR, the file is 2.3MB With legacy, the file is 2.7MB. Can we expect an optimization any soon?
t
Votes required from our part to expect changes :)
b
@Daniele B do you use any other libraries than kotlin-react & co? E.g. kotlinx-coroutines?
d
@bashor in the shared code I use coroutines
b
honestly kotlinx-coroutines is heavy, we are going to address it, but not very soon
d
@bashor more or less than 1 year?
I am using Ktor in the shared module, which I am calling from a coroutine
Ktor’s
get
is a suspend function, so you need to call it from a coroutine.
Does it mean that it’s not advisable to use Ktor with JS?
b
likely we will not be able to look at it seriously until we release IR based compiler
To be clear it’s not about suspend, it’s only about kotlinx-coroutines library and as consequence about libraries depending on it (directly or indirectly).
IR compiler already works better with it, but some libraries, like Ktor, use kotlinx-coroutines a lot.
d
is filesize the main issue with kotlinx-coroutines on JS, or there are also other issues?
when do you expect to release the IR based compiler?
b
is filesize the main issue with kotlinx-coroutines on JS
could please clarify your question -- is it about issues in kotlinx-coroutines or about size in JS, in general?
when do you expect to release the IR based compiler?
hope for next major release 🤞
d
could please clarify your question -- is it about issues in kotlinx-coroutines or about size in JS, in general?
Ktor seems to work well in my project I was just concerned with the JS filesize
I would expect it would be possible to minimize the JS file
b
@turansky Speaking about mentioned issues: I don’t believe that they will help much in cases like this because they firstly related to consuming JS produced by Kotlin, it’s not case here. But I think they could help to remove unused exports when consuming generated code from JS.
t
I don't believe that they will help much in cases like this because they firstly related to consuming JS produced by Kotlin, it's not case here
@bashor 1. Webpack works after Kotlin 2. React declared in this case. Only
react
- 200KB. And it included fully, only because Kotlin/JS doesn't support ES module format. It looks like important unresolved problem.
n
I was facing the same problem and failed to get a solution. I had to switch from using ktor client to using javascript fetch API. My bundle size reduced from 2.6MB to 700KB.
t