honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
19.96k stars 570 forks source link

feature request: minify (at runtime ?) template literals? #1211

Open charnould opened 1 year ago

charnould commented 1 year ago

Context

Hono is about performance.

For example:

Use case

Capture d’écran 2023-06-29 à 17 49 55

Questions

yusukebe commented 1 year ago

Hi @charnould

We could create a "Minify Middleware". I believe this middleware may resolve most of your problems.

The challenging aspect is that it needs to detect the proper minify algorithm based on the content-type such as HTML, JavaScript, CSS, and others.

niklasgrewe commented 1 year ago

@yusukebe i also plan to use hono for my own website. A minify middleware would also help me a lot, especially for the html templates. Do you plan to include this middleware? Is it possible to wait for it?

yusukebe commented 1 year ago

Hi @niklasgrewe !

I have an idea to implement a minify middleware and I'll try it later, may be soon!

niklasgrewe commented 1 year ago

@yusukebe awesome, thank you very much for your effort on this project, it's clean, simple and powerful 👍 One question for clarification: are template literals more efficient/faster than the jsx middleware? to be honest, sometimes I don't know where the differences or the advantages and disadvantages are...

RobertSasak commented 1 year ago

I understand that it may be challenging to implement it for all requests. In the meantime, you can simply do it on a per-handler basis.

import * as minifyHtml from '@minify-html/node'

app.get('/compress, async (c) => {
    return c.html(minifyHtml.minify(Buffer.from(html`...`), {}).toString())
})

It would be cool if c.html() accepts also Buffer.