elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.51k stars 661 forks source link

Request: Lazy loading of functions #2166

Closed ishmum123 closed 3 years ago

ishmum123 commented 3 years ago

This is a feature request.

AFAIK there is no option for lazy loading modules. A common use-case for this is where the system has major sub-sections which are generally distinct but have some communication mechanism. This feature becomes an absolute necessity for large projects. Is there any plans for this in the near future? I would be willing to contribute if someone provides a guideline on the implementation.

github-actions[bot] commented 3 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

evancz commented 3 years ago

The easy way to do this is to compile your project into N separate elm.js files, and switch between them at certain points. So instead of one "single page app" you have four or five "single page apps".

It is not a perfect stopgap, but I recommend looking into projects like elm-spa for 3rd party efforts on how to do this kind of thing.

This is something that I would like to solve in a nice way, but I believe it is interconnected with many other features (like server-side rendering) in ways that make this quite a large project. These are some of the topics I am currently exploring.