Search code examples
canjscanjs-view

CanJS: how to package view templates for production


What is the optimal way of packaging view templates for production use?

I have a number of .stache files. In development they are loaded synchronously with can.view(). In production i want to avoid multiple HTTP requests.

What is the right way to do it? Should i bundle them as single html file or single js file? Which format does StealJS use?


Solution

  • This is what I created can-compile for. For example

    can-compile **/*.stache --out views.combined.js --can 2.1.0

    Compiles all Stache files in the current folder and all subfolders into views.combined.js.

    If you use Steal and the latest steal-tools (which is currently pending a release) and you import your modules e.g. using ES6 with

    import template from 'my/template.stache!';
    

    The view will be built into the production bundle automatically (and also loaded asynchronously in development).