DEV Community

Cover image for 🎙️We build HMPL to help developers make web apps smaller in size🔥
Anthony Max Subscriber for HMPL.js

Posted on

74 17 16 16 18

🎙️We build HMPL to help developers make web apps smaller in size🔥

Today, trends in website creation are changing. With the advent of Next.js, most developers have started using the concept of SSR (Server-Sider Rendering), which allows generating dynamic markup directly on the backend. But since this practice is architectural due to the fact that it is a framework, you will not be able to combine it normally, for example, if your site is already written in Vue.

The microfrontend concept helps in this regard, but again, for budget development this is too expensive a scheme, so in order to painlessly implement SSR (without robots), this template language was developed.

🐜 HMPL

HMPL is a template language that complements regular HTML with request objects. That is, you can describe directly in the markup what API path you want to get the component.

import hmpl from "hmpl-js";
// We create a constructor function
// that will generate instances to receive our elements.
const templateFn = hmpl.compile(
  `<div>
    <h1>
      {
        {
          src: "http://localhost:8000/api/getTitle"
        }
      }
    </h1>
  </div>`
);
// Generate an instance and get an element from it
const content = templateFn().response;
// Mounting our element into the DOM
document.querySelector("#app").append(content);
Enter fullscreen mode Exit fullscreen mode

🌷 Example App

Using this module, a gallery application was created that implements dynamic content delivery on the server.

The example itself is located in the GitHub repository here.

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

💎 Star HMPL ★

📊 Size comparison

Let's compare the code of two applications with the same UI and look at their size:

Size comparison between HMPL App and Vue App <br>
(or can be any popular framework or library)

As we can see, the HMPL clicker has a smaller file size than the same Vue clicker interface.

Also, there is a comparison with other popular UI creation tools and pure JS:

comparison

The results are based on a comparison of the sizes of applications presented in this repository.

⚙️ Installation

  • Node Package Manager: You can download it via npm using the command npm i hmpl-js

  • Content Delivery Network: You can include a file with a dependency via CDN using the following code:

<script src="https://unpkg.com/json5/dist/index.js"></script>
<script src="https://unpkg.com/hmpl-js/dist/hmpl.min.js"></script>
Enter fullscreen mode Exit fullscreen mode
  • Locally: Or, there is a similar option with the second one, just download the file to your local machine.

💬 Feedback

You can write your thoughts about the module in the comments, it will be interesting to read! Or, there is a thematic discord channel for questions and suggestions, there I or someone else will try to answer!

✅ This project is Open Source

So you can take part in it too! This also means you can use it for commercial purposes:

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

Thank you for reading!

Thanks!

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (19)

Collapse
 
poetro profile image
Peter Galiba

The size comparison is really misleading. You also need server side code for any of the features demonstrated here, where the Vue implementation is complete.

Collapse
 
louis_cassany_24f86a9c20b profile image
Louis Cassany

Does that mean that with the server code you may even get a bigger bundle size in the end ?

Collapse
 
anthonymax profile image
Anthony Max

How? The code remains on the server, you transfer the framework via protocol. Another advantage is that this HTML can be transferred between sites.

Collapse
 
anthonymax profile image
Anthony Max

No, wait, it doesn't. Yes, you essentially transfer the code from the client to the server, but this code remains on the server, and the clients load only the framework, into which HTML from the server goes brick by brick. Accordingly, this framework will be loaded during the first and subsequent loads, accordingly the site will load faster, but heavy elements will simply be with a loader.

Collapse
 
poetro profile image
Peter Galiba

But you still need to write the server side code, which means you are writing more code than in the Vue version. The client side code difference doesn't even matter as you will be downloading more from the server through the additional requests.

Thread Thread
 
anthonymax profile image
Anthony Max • Edited

Well, yes, you still have to write code, but on the server - that's clear. No module will replace it). Regarding the value on the client - it matters. If the site is focused on SEO in search results, then the initial loading is of colossal importance. Literally, the sales funnel will simply sag for the banality that the site loads for 10 seconds, when with this approach the site will load almost instantly, because there will be nothing to load, but all components will be with loaders that come from the server. There are also pros and cons here. In fact, I am retelling the SSR advantages.

Thread Thread
 
cyanchanges profile image
Cyan

I guess the Vue version and the HTPL version code behaves differently?
The Vue code stores the temporary state on the client.
But HTPL seems stores on the server.
That introduce latency, and the effect isn't the same.
And you can use Composition API instead of Options API, for a shorter code.

Collapse
 
dansasser profile image
Daniel T Sasser II

This is the second time I have seen something about HMPL in my news feed so I guess I'll give it a test drive 😉

Collapse
 
anthonymax profile image
Anthony Max

Thanks, let's do it! If you find a bug, write to us - we'll fix it! We did 100% test coverage, but we could have missed something.

Collapse
 
louis_cassany_24f86a9c20b profile image
Louis Cassany • Edited

The size comparison is not very impressive, you don't gain that much for the added complexity and dependency.

Collapse
 
anthonymax profile image
Anthony Max

And what - honesty is the main thing. Yes, maybe it doesn't win much, well, why should I write now that it reduces by 100 times and lie? I write honestly, what is, is. Even if we take a modern web application with 100 modules with boilerplate code, well, there may be such a result, but everything is honest. I will not deceive.

Collapse
 
cyanchanges profile image
Cyan

Don't use Vue Options API, use Composition API, and the code will be shorter.

Collapse
 
rufatalv profile image
Rufat Aliyev

Good!

Collapse
 
john_coding profile image
John

Good article! And how does this work?

Collapse
 
anthonymax profile image
Anthony Max

Thanks! The components are taken from the server, so on the client we only have the request markup.

Collapse
 
anthonymax profile image
Anthony Max

The diagram doesn't look very good, but it looks cool on the website, with animation.

Collapse
 
paulbrowne profile image
paulbrowne • Edited

probably better to source the minified version of json5

<script src="https://unpkg.com/json5/dist/index.js"></script>
<script src="https://unpkg.com/json5/dist/index.min.js"></script>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ktbsomen profile image
somen das

I am creating a more simple approach to make web apps.
i added support for loops ,if-else inside of plain old HTML*

check the article on dev.to

dev.to artical link

Collapse
 
paulbrowne profile image
paulbrowne

Pretty sure ht.js is smaller...

If you are going to rely on json5, then probably better to just bundle it with this framework?

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more