Nuxt.js: HTML minify slow in generate

Created on 20 May 2017  ยท  13Comments  ยท  Source: nuxt/nuxt.js

I find that minifying the HTML in generate takes around 100ms for each rendered route, which seems unreasonably slow: my ~400 routes generate at 70 seconds but if I deactivate minify I shave off a full 40 seconds! Any idea on how to speed up minify?

This question is available on Nuxt.js community (#c639)

Most helpful comment

@ausir0729 I really love your answers! Really great content inside!

I'm adding the option to disable the html-minifier by setting generate.minify: false in nuxt.config.js. No need for a PR :)

All 13 comments

Unrestrained idea :

give up node.js html minify .

after you build , run a golang html minify lib .
( don't know it will be faster ? )

maybe you can try , make a benchmark
https://github.com/tdewolff/minify/tree/master/cmd/minify

It certainly aught to be faster. Good input, anyone else? What about the
cluster module?

On Sat, 20 May 2017 at 16:31, Ausir Lo notifications@github.com wrote:

Unrestrained idea :

give up node.js html minify .

after you build , run a golang html minify lib .
( don't know it will be faster ? )

โ€”
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/nuxt/nuxt.js/issues/746#issuecomment-302876717, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAc7io9KcrOWNlmTb-Fdg_cgKrBPAxv1ks5r7vk_gaJpZM4NhTkL
.

@jroxendal
honestly , nuxt.js just use html-minify package , If you want enhance html-minify , it should be report on html-minify repo . Suggest it use muti-thread minify , or find another more effectiveness html minify packeage , let nuxt.js developers check it can be better than html-minifier or not .

just my personal opinion .

If you want maximum speed , use go/c bin file to minify html file maybe can get fastest processing time .
just modiy your package.json file "generate":"nuxt generate" to "nuxt generate && ./minify dist"
try it . I don't have 400+ html in project , so , maybe you can try this solution .

my personal interest
I tried benchmark about default html-minifier and golang html minify.

result

| | html-minifier 400 | go minify 400 | html-minifier 4000 | go minify 4000 |
|---------------------|-------------------|---------------|--------------------|----------------|
| generate each file | 120ms | 25ms | 120ms | 25ms |
| total generate time | 79.87s | 53.28s | 627.32s | 327.20s |
| minify time | โ‰’ 80ms * 400 = 16s | 0.71s | โ‰’80ms * 4000 = 320s | 7.37s |
| save | | 26.59s | | 300.12s |

seems you can use go html minify to save you generate time .
@jroxendal for your reference .

TL;DR

I just copy my index.vue to minify-test/_test.vue
and generate 400 and 4000 routes generate .
first generate with default html-minifier setting , second generate is set all html-minifier setting to false , after generated run go html minify command all dist folder minify.exe -o dist/ -r dist

first test

400 routes with default setting
screenshot_7

400 routes with go minify
screenshot_10

second test

4000 routes with default setting
4000-default

4000 routes with go minify
4000-go

test computer
screenshot_11

@Atinux
seems like no config can just skip html-minifier , if can just skip html-minifier maybe can save more generate time . just a suggest for features ( maybe can wait someone PR ๐Ÿ˜† )

@ausir0729 I really love your answers! Really great content inside!

I'm adding the option to disable the html-minifier by setting generate.minify: false in nuxt.config.js. No need for a PR :)

@Atinux I already done add generate.minify : false
and make test report .
I will PR few mins later .

Please PR into dev branch @ausir0726

forget the PR , you already finish ๐Ÿš€ nothing better .

This was great, thanks @ausir0726!. I have a PR on the way that improves render times for dynamic routes, combined with this even thousands of routes should generate and minify quickly ๐Ÿ‘
@atinux you want all PRs to dev?

From now on, all PR should be on dev yes :)

@ausir0726 is this works for nuxt express template?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikekidder picture mikekidder  ยท  3Comments

gary149 picture gary149  ยท  3Comments

bimohxh picture bimohxh  ยท  3Comments

vadimsg picture vadimsg  ยท  3Comments

vadimsg picture vadimsg  ยท  3Comments