When comparing swig vs Marko, the Slant community recommends Marko for most people. In the question“What are the best JavaScript templating engines?” Marko is ranked 10th while swig is ranked 14th. The most important reason people chose Marko is:
Marko consistently outperforms other alternatives in code benchmarks, both on rendering speed and compilation time.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Works both on the client and on the server
Available for node.js and major web browsers
Pro Does not hide HTML
Swig does not abstract HTML syntax from you (like e.g. Jade does) giving a certain filling of control over the markup.
Pro Extremely fast
Marko consistently outperforms other alternatives in code benchmarks, both on rendering speed and compilation time.
Pro Custom tags
Custom tags provide a simple mechanism for embedding more complex components into a template by extending the HTML grammar with support for new tags. For example:
<div>
<say-hello name="World"/>
</div>
Custom tags are easy to create since they just map to a JavaScript "renderer" function as shown below:
module.exports = function sayHelloRenderer(input, out) {
out.write('Hello ' + input.name + '!');
}
Custom tags support nested content:
<fancy-overlay title="My Title">
This will be the body content of the overlay
</fancy-overlay>
Custom tags can also have parent/child relationships to support more complex use cases such a "tabs" component with nested "tab" components:
<fancy-tabs>
<fancy-tabs:tab label="Home">
Content for Home
</fancy-tabs:tab>
<fancy-tabs:tab label="Profile">
Content for Profile
</fancy-tabs:tab>
<fancy-tabs:tab label="Messages">
Content for Messages
</fancy-tabs:tab>
</fancy-tabs>
Pro Streaming
Streaming allows progressive HTML rendering and reduces time to first byte.
Pro Server-side rendering
Marko supports both server-side and client-side rendering.
Pro Marko Widgets
Marko Widgets allows UI components (rendering + behavior) to be built using Marko.
Pro Compiled templates are readable CommonJS modules
Avoids ugly globals and "named" templates.
var template = require('./template.marko');
var html = template.renderSync({name: 'Frank'});
Pro Asynchronous rendering
Marko makes additional asynchronous calls after the view rendering has begun.
Pro Lightweight runtime (~4 KB gzip)
Pro Easy to integrate with express.js
Easy Integration with Express and Node
Pro Documentation is well maintained and helpful
The documentation is extensive and very helpful. It also contains several sample applications which are very useful.
Pro Allows JavaScript expressions
JavaScript expressions can be executed inside the templates.
Pro Simple and readable syntax
Marko has a HTML-like syntax which should be easy to read and understand for everyone who has even minimal experience in web development.
Pro Short learning curve
It is easy to get up to speed and understand what is going on in a very short period of time.
Pro Small compiled templates
Marko's compiled templates are usually very small, as proven by benchmarks.
Pro Lots of tests
To prevent regressions, Marko includes a full suite of tests. The testing harness renders a collection of templates and does an exact string comparison to make sure that the tests rendered exactly as expected. There are also API tests, and negative tests to make sure that errors are reported in a friendly way.
To run tests:
git clone https://github.com/marko-js/marko
cd marko
npm install
npm test
Pro Friendly compile-time error messages
Error messages come in an easy to read and friendly format, with valid stack traces and file formats of the file(s) which brought the error(s).
Pro Concise and Mixed syntax
The Concise syntax type lets you write Marko with a Jade-like indentation based syntax, and the Mixed mode lets you combine in regular HTML-style syntax.
Pro Server and client logic can easily be expressed within the same template
Pro Has a very active and interactive community
Marko's development community is rather small compared to other frameworks but community is well mannered and active. You can chat with the core development team using gitter.im
Cons
Con No updates for at least 6 months
Swig has not received any new commits since June 25 2015.
Con If you want to get the full experience you have to use NodeJS
To use markojs's most popular feature: SSR although you can use any language based server as a backend. It is rather complicated.
Con Very opinionated and not customizable enough
Some custom use cases are not possible. For example, trying to build an AMP page using Marko can be very challenging (special style tag requirements are hard to work with, also, Marko by default inserts a script tag into the rendered output html which is invalid in AMP and needs to be manually removed, etc..)