ect icon indicating copy to clipboard operation
ect copied to clipboard

Precompilation of templates

Open kesavkolla opened this issue 11 years ago • 10 comments

ECT is an excellent template language. I like the way it support the client side templates using the middleware compilation. Is there any way to use the client side templates with pre compiled templates. I don't have a running node middleware on my hosting server. I want to precompile all the templates on my dev server and include the result js directly in my client app. Is there any way to achieve this?

Thanks -Kesav

kesavkolla avatar Feb 05 '13 03:02 kesavkolla

This feature planned for next version.

baryshev avatar Feb 05 '13 21:02 baryshev

Awesome. A batch compiler for ect templates and the output can be directly served to browser. It would be great if this can be integrated with Angular.js. Also cool thing would be to integrate with CodeKit so that it can auto compile the ect templates. I'd love to see this feature soon.

kesavkolla avatar Feb 06 '13 01:02 kesavkolla

Hey guys!

First of all, I would like to thank everyone, this is project is really impressive and helpful.

I've adapted the code so I can precompile the templates. If anyone is interest, please check my fork: https://github.com/eliseumds/ect

eliseumds avatar Apr 12 '13 20:04 eliseumds

Previously we used eco with spine.js and hem. I would love to replace eco with ect in the spine.js docs, example apps and and hem and all that but precomplilation would be a requirement. I will keep an eye out for this feature landing. looks like you guys are doing good work. Keep going!

aeischeid avatar Apr 16 '13 17:04 aeischeid

First version of command-line compiler released just now (with v0.5.0). It have a basic functionality for now, but will be improved in future.

baryshev avatar Apr 26 '13 23:04 baryshev

Hey All, What's the status of precompiling templates on the client side? I love ECT, but this is the only thing preventing me from integrating it. Currently the pre-complier outputs an anonymous function... how would one integrate the compiled output to be renderable by an ECT object instance?

I dug into the source a little bit... I was thinking maybe adding a method like:

renderer.register({ name:'foo', compiled:(function(){}) });

... this would add a record to the cache object internally

Then I would be able to:

renderer.render('foo',{});

I'll submit a patch if I end up writing it, but wanted to get your thoughts.

mwcollins avatar Sep 11 '13 17:09 mwcollins

If you need to serve all precompilied templates to client in one script/html (without ajax lazy load) you can use this syntax:

var renderer = new ECT({
    root : {
        foo: 'ectPrecompilledFuncitonHere',
        bar: 'ectPrecompilledFuncitonHere'
    }
});

After that you can use template foo and bar in your code.

baryshev avatar Sep 11 '13 20:09 baryshev

Solid, thanks... is that the string source or is it the function reference?

mwcollins avatar Sep 11 '13 20:09 mwcollins

This is a string as it outputted by ect command line tool.

baryshev avatar Sep 11 '13 20:09 baryshev

Unfortunately, I find this woefully inadequate. In my opinion ECT beats ECO all around, except for the fact that you're coupled to a server side implementation, and lazy loading the templates async.

My project has hundreds of templates - I doggedly control when those templates are loaded on the client. When a user visits a new page, I send down all the JS including the template code as one file. That way, the minimal code is loaded when the page first loads, but complete "page modules" are loaded lazily when they're needed.

It wouldn't make send to send the templates 1 file at a time on demand.

So that means that there needs to be a way to precompile them into a global namespace. Many templates already do this, ECO, EJS, Handlebars, Jade, etc. ECT not providing this is a real deal breaker.

brian-mann avatar Mar 07 '14 03:03 brian-mann