I was considering using Dart for a Framework I was going to write. One of the issues I found was that I could not lazy-load my classes or perform some alternative method of loading more code. I wish to dynamically load more code when the user browses to different areas of the site without reloading the page ((ab)using the history API), but from what I could tell I would have to load all of the code upfront. This just wouldn’t work because it would give terrible first-load times and every time I change any code the users would have to re-download all of the code for the website.
An example of a program that does this in javascript is SyntaxHighlighter. There is an option to load brushes only when they are needed.
In dart, you could load an isolate and pass some serialized version back in forth to accomplish syntax highlighting, but for my app I need event listeners and handlers and a lot of DOM and CSS manipulation, there is no way that I am going to write a custom API for doing all of this with primitive types.
I was wondering if there was a way to accomplish this in Dart or if there is anything in the works that would allow this technique to be implemented. (or else it is back to JavaScript).
Thanks, Kevin
To my knowledge there is no way to load code dynamically on the fly into an already running Dart program (although this might change when reflection arrives in Dart).
You could load a different Dart program and then communicate with it using postMessage but that seams a bit overkill. Perhaps you should open a bug for it. We also have a large Dart code base and could definitely use something like GWT code splitting to speed it up a bit.