Closed LeonDWong closed 7 years ago
@LeonDWong , I think including the compiler in browsers is not a good idea. Some tips:
@aMarCruz It's a good idea to render pug template in server end or compile it to html by tools(like brunch, gulp, etc).But if i get a piece of pug template from server and data is in browser, i have to render them via browser end compiler.So i still try to find the way to minimize Pugjs in browser.
You can compile the template to JavaScript on the server side using pug.compileFileClient or the --client flag on the CLI. This still lets you add the data on the client, but means you won't need the full pug compiler.
@ForbesLindesay Thx.It's sort of tricky, but i still wonder is it impossible to minimize the size of Pugjs in browser?
No, it can't really be reduced in size, since it is a full compiler. This is what allows pug to be a powerful templating language. Even if we could reduce the file size, the compilation process is far too slow to run on every client's browser. We also make no effort to make that code work in anything other than the latest version of google chrome.
If you need a templating language that is simple enough to build in the browser, I suggest somethign like: https://mustache.github.io/
I love using jade/pug in the browser for interactive demos and it makes it a great candidate for component based design tools. jade.js
used to be 41k minified and was blazing fast to compile templates in the browser. I’m curious: why is the file size of pug.js
10x bigger and thus also slower?
It was always slow. We have optimised for the pre-compiled use case as that is the only way to get reasonable performance. The trade off is that compiling on the fly is now slower.
Pugjs in browser is nearly 500K.Anyway to minimize it?Thx.