0

Is there any good way to build Dart app with Web-UI and dynamically loading over network new HTML templates (client side templating)?

It looks like Web UI templates are always load together with generated *.js files:

  <head>
    <!-- this will be transformed by WebUI compiler to *_generated.js code -->
    <link rel="components" href="common_templates.html"> 
  </head>
abdolence
  • 2,369
  • 1
  • 21
  • 29

3 Answers3

0

I am working toward a single page application that dynamically loads new content into the content section of the page based on the menu selected on the left. The content section gets populated from a WebUi component, but it does happen dynamically, and it does happen client side. On the menu, I have something like;

        <li> <a href="#/active">Active</a> </li>
        <li> <a href="#/completed">Completed</a> </li>

where i have the application respond to the hash changing when a menu item is clicked. They do something similar in the WebUi implementation of the ToDo app.

The content has a conditional template that loads a WebUi component based on the menu selected.

This may not be what you had in mind. Please provide more details if I am off track here.

Allan
  • 83
  • 5
  • Sorry, but this is not the answer I'm looking for. I'm trying to dynamically _load over HTTP_ new templates suitable for WebUi. It's not good load in one page all templates. Of course I could divide to many pages on the server side, but this is require server side templating. – abdolence Feb 28 '13 at 05:32
  • 2
    With regards to the "it's not good load in one page all templates" - You might be interested in tracking this bug: http://dartbug.com/3940 - it's about splitting the output of dart2js to allow deferred loading of parts of your app. Not web-ui specific, but would allow more general splitting of your app into smaller parts that are loaded dynamically. – Chris Buckett Feb 28 '13 at 09:05
0

Currently it's not possible to dynamically load and process templates with WebUI. WebUI needs to process the templates ahead of time. I think @ChrisBuckett suggestion from the other answer/comments would be a great way to go: use deferred loading when it becomes available.

Another crazy idea would be to ship the web-ui compiler with your app and process the templates in the browser. Note, this is not even possible today because web-ui currently cannot be compiled with dart2js (it has some dependencies on dart:io). Hypothetically, if it were possible, it's likely going to be a lot bigger than shipping the extra templates. So, if your goal was to reduce the initial download, then this idea is a no-go.

Siggi Cherem
  • 369
  • 1
  • 3
  • Yes, I think about use web-ui compiler with my app, but you right - this is really crazy :D Anyway - it is looks like there is no way to do it for current implementation Dart+WebUI and I accept this answer. – abdolence Mar 02 '13 at 09:55
0

It is now possible to performed delayed loading of Dart code. If your client side templates are implemented as Dart source, you can use the DeferredLibrary class.

A more detailed article will likely show up soon in the articles section of Dart website.

Greg Lowe
  • 15,430
  • 2
  • 30
  • 33