hmpl is a small template language for displaying UI from server to client. It is based on customizable requests sent to the server via fetch and processed into ready-made HTML. The language is syntactically block-based and integrated with JSON5 and DOMPurify. Reduce the size of your javascript files and display the same UI as if it was written in a modern framework!
☆ If you find HMPL useful, please consider giving us a star on GitHub! Your support helps us continue to innovate and deliver exciting features.
In this example, we create a dynamic clicker component in which, when a button is pressed, we will receive the value of the current clicks that will come from the server. The advantage of this approach is that we can take out not only data in the form of Text, but also entire components and even pages!
If you need an option without using js, then by connecting the additional hmpl-dom module you can do this.
This way, components from the server are mounted into the DOM without having to add them manually. This is great when you want to replace Alpine.js or HTMX in a project.
Using template language capabilities, you can multiply reduce the size of the application bundle. Full customization of the request based on the modern fetch standard, as well as support for all the functionality necessary for modern work in applications (request indicator, sending by event, automatic generation of body for the form, caching) and the syntax of the object in the markup, which requires a minimum number of characters, will help to build interaction with the server and client as efficiently as possible. App size comparison (bytes):
Also, HMPL can be a great alternative to popular tools such as HTMX and Alpine.js.
- Customizable: Send a custom request to the server when receiving the UI
- Memory Preserving: Reduce file sizes on the client by several times
- Based on Fetch API: Use a modern standard instead of XMLHTTPRequest
- Server-oriented: Work with the server directly through markup and with a little js
- Generate thousands of DOM nodes from a single template: Work with large components not only on the server but also on the client
- Simple: Get ready-made UI from the server by writing a couple of lines of familiar object syntax
- Protected from XSS attacks: Enable incoming server HTML sanitization with DOMPurify and work with it safely
- Flexible: Can be used in almost any project due to not only working through a script, but also working in files with the .hmpl extension
- Integrated with JSON5: Flexible writing of objects by docs as in vanilla js, as well as the reliability of the parser used by millions of people
- Small bundle size: Lots of functionality in a couple of kilobytes
hmpl can be installed in several ways, which are described in this section. This tool is a simple javascript file that is connected in the usual way through a script, or using the import construct in an environment that supports this (webpack build, parcel build etc.). Also, starting with version 2.2.0, the JSON5 module needs to be connected, and starting with version 2.2.5, the DOMPurify module also needs to be connected. The first and easiest way is to install using a CDN.
This method involves downloading through npm or other package managers.
Node.js v10.12.0+ is required.
Along the path node-modules/hmpl/dist you can find two files that contain a regular js file and a minified one.
This method involves connecting the file through a third-party resource, which provides the ability to obtain a javascript file from npm via a link.
This resource could be unpkg, skypack or other resources. The examples include unpkg simply because it is one of the most popular and its url by characters is not so long.
There is a starter project on Vite.
Based on it, you can make web applications.
The documentation contains main information on how the HMPL template language works. If you have any questions about how HMPL works, you can use the following resources:
- Github - In the discussion and issues sections you can ask any question you are interested in
- Discord - You can ask your question in the thematic channel "support"
- 𝕏 (Twitter) - There is a lot of interesting stuff there, concerning the template language and not only :)
You can also ask your question on Stack Overflow and address it in the resources described above.
We have a Contributing Guide that describes the main steps for contributing to the project.
Thank you to all the people who have already contributed to HMPL, or related projects!
The project has a roadmap where you can see the plans for future development.
Licensed under MIT
.png)


