Building a Static Site with Components such as Nunjucks

Its surprising to see but nevertheless a very important development in web development, to build websites with different components. Well, to understand this, you have to imagine a page and then another page and then yet another page. Building pages one by one can get quite tedious. Building a website with components essentially implies that you are building separate components, like a call-to-action form, a search form, as separate components and then just piecing them together with those components.

Static websites are slowly becoming quite a rage and this is rightly so because they are easy to navigate and even easier to develop. There are several JavaScript frameworks that emphasize this movement quite ferociously and several of these static websites are being built using different JavaScript template engine, Nunjucks being a popular one.

Let’s look at it from the version of a Microsite. It doesn’t require a sophisticated CMS that handles hundreds of different pages. It doesn’t even require any Java framework for its interactivity. All it needs is a set of pages with the same layout. If you are looking at HTML as a solution, you’re not going to find it there. The next natural choice would be PHP language but static sites don’t support PHP so Nunjucks comes to the rescue. When you are looking to create a layout, you are essentially looking at different elements of that layout including the header, footer.

 

The advantage of using Nunjucks is that it has been created to implement a complete lexer and parser which can then generate an AST along with a compiler, which allows it to compile to raw JavaScript. If you were to compare it to any other frameworks, it would be as fast as jinja2, only with a rendering time of a few milliseconds.

If we were to continue comparing, Nunjucks also allows for client-side browser rendering, something which you won’t be offered by jinja2. This allows you to pre-render complicated pages and factor in any changes in data by using the same templates that you have used for anything else.

Posted by Shweta Urmaliya

Meet Shweta, a seasoned blog author with over 14 years of expertise in product management, people management, and project coordination. Her wealth of experience allows her to provide valuable insights on navigating the ever-evolving landscape of these fields. Join Shweta as she shares her knowledge and tips for success in her engaging blog posts.