Kotlin.js file size


As I understand, client side must always load the kotlin.js file first, then our application js files. I guess, client will never need kotlin.meta.js (123 KB) and this file is only used when transpile kotlin to js, is that correct?

The kotlin.js file size is 1.21 MB. If I minify this file, I will get ~600 KB (use jscompress.com). Compress the minified js to gz will reduce size to ~100 KB (Result of http://archive.online-convert.com/convert-to-gz). For comparison, here is the size of other frameworks: https://gist.github.com/Restuta/cda69e50a853aa64912d. Size of React is quite small when compare to Kotlin or Angular 2.

Don’t you think it is too big when using for web frontend because user needs to wait to download a big js file? Is there a plan to separate into smaller modules and only include what we need? Or does anyone have ideas to improve startup time when user visit our website the first time?


Sure, we are working on it. There are several possitble solutions to reduce kotlin.js size:

  1. Write our own tool that removes unnecessary parts of JavaScript files produced by Kotlin compiler.
  2. File-to-file compilation, when each Kotlin source file compiles to single JavaScript file. Tools like WebPack should remove unnecessary JavaScript files.
  3. Generate code for Google Closure Compiler. It’s very specific way, since GCC in advanced mode imposes restrictions on the code, and not all JavaScript libraries follow these restrictions.
  4. Compile program as a whole. This allows to perform dataflow analysis during compilation and derive which code is ever used.

I think we need all four options implemented someday. However, the easiest way for now is (1). We have a prototype of such tool that is capable of reducing miminal Hello Word application down to ~60 kilobytes. Another approach that we can implement in the near future is (2), it’s important, since modern JavaScript ecosystem uses file-to-file compilation.


Let me adress the elephant in the room, instead of a fancy transpile and glorified minification system how about grouping by purpose all functions in different js files in a class like fashion and using AMD (RequireJS for example) this will require files async allowing fast loads no matter how absurdly big kotlin.js becomes.

Kotlin should take lib size seriously, come on 1mb file just for a cleaner syntax, no one besides heavy single paged enterprise apps (and not even them) is willing to make the webapp that heavy, is simply unacceptable especially when EcmaScript 6 is about to become de facto in all browser.

I belive Kotlin has a bright future but this kinds of decisions will determine its path at least in the near future, and imo the weight of kotlin.js is a con that currently wins any posible pro and I belive there is many more people on the same boat.


GCE tooll available in 1.1.4 dev build reduces std lib size to ~300kb on my medium sized project(about 2mb compiled)
I would say this is god enough.


It also will be very good to have an official CDN for kotlin std lib.


300kb is of course bereable but this will grow over time especially the more complex your app gets this will just not happen using AMD async pattern.


it is 300kb pre minified so about angular 1.x size (minified) or 2x jquery
current js output is nowhere as good as say GWT output but i would argue after GCE tool and minification code size is not that big of a problem already.
the more complex app gets the larger part of it is app code itself.
current js compiler output looks like very direct translation of classes which is good for in browser debugging with sourcemaps or not. I yet to see other way to debug js targeted solutions without browser that actually works good. GWT had one few years ago but it was way too slow, tricky to use and very complex inside for non trivial projects.


Maybe this is the reason why Kotlin.js cannot be packaged into react native js bundle


It can’t be packaged by react-native because it’s too large. If you use the DCE tool, it can be. https://kotlinlang.org/docs/reference/javascript-dce.html

I’m trying out some better solutions, such as compiling the stdlib into multiple js files.