DEV Community

Cover image for 🐜 HMPL.js: Small Template Language. Reduce the build size several times πŸ“¦
Anthony Max Subscriber for HMPL.js

Posted on

🐜 HMPL.js: Small Template Language. Reduce the build size several times πŸ“¦

TL;DR

When you work with modern frameworks, the first question that comes up is the size of the bundle you generate.

Yes, of course not first and foremost, but the client doesn't care how the developers do the project. He wants the site to load quickly!

So, in this article I would like to look at a small template language that will help you make the same application, but with much less effort.

Well, let's see what this project is πŸ”Ž


πŸ‘€ Is there an example of reducing the build size?

We'll take a specific application on Next.js and HMPL.js and see how much it will weigh in the end.

πŸ“¦ Next.js build:

Next.js

πŸ“¦ HMPL.js build:

HMPL

This build is 10x smaller than the Next.js build. Moreover, we keep the interface in its original form, without losing any advantages (except for indexing by robots).

Interface

This is just a regular landing page without any frills. Just a couple of animations in the banner and a countdown for a limited offer.

Also, it would be great if you supported the project with your star! Thanks ❀️!

πŸ’Ž Star HMPL β˜…


πŸ“Š How does it compare to other modules?

Obviously, it's not entirely fair to take Next.js, since it's a bit different, but nevertheless it's fair, because our goal is to make a site with a good interface, and for this purpose all means are good.

But let's try to compare it with similar modules:

Comparison

And here too it is clear that the applications from this test are smaller in the result, even if we compare them with Alpine.js, which essentially does the same thing.


πŸ–‹ What does the syntax of a template language look like?

The template language provides the following block extension for HTML:

<div class="wrapper">
  {{#request src="/api/my-component.html"}}
    {{#indicator trigger="pending"}}
      <p class="my-indicator">Loading...</p>
    {{/indicator}}
  {{/request}}
</div>
Enter fullscreen mode Exit fullscreen mode

Here, we are describing a certain component (which is not really a component, since it is a helper block), but nevertheless, for general understanding it is perfect. Instead of it (like outerHTML), we load the HTML that comes to us from the server.


βš™οΈ Try this project

  • Package Manager: You can install it by typing npm i hmpl-js in the terminal
  • CDN Method: You can load these libraries directly from a CDN by embedding the following script tags in your HTML:
  <script src="https://unpkg.com/json5/dist/index.min.js"></script>
  <script src="https://unpkg.com/dompurify/dist/purify.min.js"></script>
  <script src="https://unpkg.com/hmpl-js/dist/hmpl.min.js"></script>
Enter fullscreen mode Exit fullscreen mode
  • Local Setup: If you prefer offline usage, download the files and host them yourself - functionality remains identical.

βœ… Our code is Open Source

So you can take part in it too! We welcome activity and want to make this project better!

GtiHub Repository: https://github.com/hmpl-language/hmpl
Website: https://hmpl-lang.dev


Thank you very much for reading this article! I hope this project will be useful to you! ❀️

πŸ’¬ What do you think? It will be interesting to know in the comments!

Top comments (8)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
anthonymax profile image
Anthony Max

Yes

Collapse
 
nevodavid profile image
Nevo David

pretty cool honestly, i always get annoyed by big bundles - you think most devs will ever pick smaller tools over easy ones like next.js?

Collapse
 
anthonymax profile image
Anthony Max

Next.js

Collapse
 
dotallio profile image
Dotallio

That bundle size difference is honestly impressive! Where have you found HMPL.js shines the most outside of landing pages - would you use it for anything dynamic or more complex?

Collapse
 
anthonymax profile image
Anthony Max

In registration and authorization forms it is quite good.

Collapse
 
anthonymax profile image
Anthony Max

It is clear that node_modules will be too large even for a normal "Hello, World!" type application.

Collapse
 
alexpa292 profile image
Alex Patla

It's obvious

Some comments may only be visible to logged-in visitors. Sign in to view all comments.