2

I would like to lazily import the definition of a function in Elm. The use case is the browser, where I may have multiple views that I do not need to render for initial page load, so I'd like to defer those network requests to speed up initial load. Polymer does this with their PRPL pattern, where you can lazy load the definition of a custom element. I have looked around, but haven't been able to find anything to suggest that this is even possible in Elm.

Any ideas would be appreciated. If none surface, I'll assume it's not possible.

Alexander Otavka
  • 796
  • 1
  • 6
  • 9

1 Answers1

6

I don't think this is possible in Elm. Dynamic imports are specifically, intentionally impossible in the language in order to statically check them at compile time.

You might be able to work something out with ports to your JS program that dynamically run or fetch other Elm modules, but you would be giving up a lot of the benefits you'd get from the Elm compiler.

Joseph Fraley
  • 1,210
  • 1
  • 9
  • 22