How to minify Lit-HTML (including comments)












0















I decided to try out lit-html via:



npm install lit-html --save


I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size, but by only importing the html and render exports it caused my webpack to grow over 13KB. That's much larger than expected.



Additionally, the final dist package had this embedded in it 7 times:



/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
**/


That's a bit excessive.



I thought webpack 4 was suppose to remove comments automatically. How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?



I can live without lit-html if its too intrusive.










share|improve this question

























  • I just tested this same app using viperhtml instead of lit-html and that got rid of all the legal comments but the package was even larger (because viperhtml strives to also support old browsers I don't care about).

    – Lonnie Best
    Nov 26 '18 at 10:41








  • 1





    if you are bundling viperHTML instead of hyperHTML of course it's larger, it has NodeJS stuff that has nothing to do with hyperHTML or lit-html itself. Try again with hyperHTML, in case that wasn't a typo, for surely better results.

    – Andrea Giammarchi
    Dec 5 '18 at 8:28













  • I meant to say hyper not viper. I installed it like this: npm install hyperhtml --save.

    – Lonnie Best
    Dec 6 '18 at 11:12
















0















I decided to try out lit-html via:



npm install lit-html --save


I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size, but by only importing the html and render exports it caused my webpack to grow over 13KB. That's much larger than expected.



Additionally, the final dist package had this embedded in it 7 times:



/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
**/


That's a bit excessive.



I thought webpack 4 was suppose to remove comments automatically. How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?



I can live without lit-html if its too intrusive.










share|improve this question

























  • I just tested this same app using viperhtml instead of lit-html and that got rid of all the legal comments but the package was even larger (because viperhtml strives to also support old browsers I don't care about).

    – Lonnie Best
    Nov 26 '18 at 10:41








  • 1





    if you are bundling viperHTML instead of hyperHTML of course it's larger, it has NodeJS stuff that has nothing to do with hyperHTML or lit-html itself. Try again with hyperHTML, in case that wasn't a typo, for surely better results.

    – Andrea Giammarchi
    Dec 5 '18 at 8:28













  • I meant to say hyper not viper. I installed it like this: npm install hyperhtml --save.

    – Lonnie Best
    Dec 6 '18 at 11:12














0












0








0








I decided to try out lit-html via:



npm install lit-html --save


I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size, but by only importing the html and render exports it caused my webpack to grow over 13KB. That's much larger than expected.



Additionally, the final dist package had this embedded in it 7 times:



/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
**/


That's a bit excessive.



I thought webpack 4 was suppose to remove comments automatically. How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?



I can live without lit-html if its too intrusive.










share|improve this question
















I decided to try out lit-html via:



npm install lit-html --save


I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size, but by only importing the html and render exports it caused my webpack to grow over 13KB. That's much larger than expected.



Additionally, the final dist package had this embedded in it 7 times:



/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
**/


That's a bit excessive.



I thought webpack 4 was suppose to remove comments automatically. How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?



I can live without lit-html if its too intrusive.







javascript typescript webpack-4 hyperhtml lit-html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 10:42







Lonnie Best

















asked Nov 26 '18 at 7:42









Lonnie BestLonnie Best

2,79153145




2,79153145













  • I just tested this same app using viperhtml instead of lit-html and that got rid of all the legal comments but the package was even larger (because viperhtml strives to also support old browsers I don't care about).

    – Lonnie Best
    Nov 26 '18 at 10:41








  • 1





    if you are bundling viperHTML instead of hyperHTML of course it's larger, it has NodeJS stuff that has nothing to do with hyperHTML or lit-html itself. Try again with hyperHTML, in case that wasn't a typo, for surely better results.

    – Andrea Giammarchi
    Dec 5 '18 at 8:28













  • I meant to say hyper not viper. I installed it like this: npm install hyperhtml --save.

    – Lonnie Best
    Dec 6 '18 at 11:12



















  • I just tested this same app using viperhtml instead of lit-html and that got rid of all the legal comments but the package was even larger (because viperhtml strives to also support old browsers I don't care about).

    – Lonnie Best
    Nov 26 '18 at 10:41








  • 1





    if you are bundling viperHTML instead of hyperHTML of course it's larger, it has NodeJS stuff that has nothing to do with hyperHTML or lit-html itself. Try again with hyperHTML, in case that wasn't a typo, for surely better results.

    – Andrea Giammarchi
    Dec 5 '18 at 8:28













  • I meant to say hyper not viper. I installed it like this: npm install hyperhtml --save.

    – Lonnie Best
    Dec 6 '18 at 11:12

















I just tested this same app using viperhtml instead of lit-html and that got rid of all the legal comments but the package was even larger (because viperhtml strives to also support old browsers I don't care about).

– Lonnie Best
Nov 26 '18 at 10:41







I just tested this same app using viperhtml instead of lit-html and that got rid of all the legal comments but the package was even larger (because viperhtml strives to also support old browsers I don't care about).

– Lonnie Best
Nov 26 '18 at 10:41






1




1





if you are bundling viperHTML instead of hyperHTML of course it's larger, it has NodeJS stuff that has nothing to do with hyperHTML or lit-html itself. Try again with hyperHTML, in case that wasn't a typo, for surely better results.

– Andrea Giammarchi
Dec 5 '18 at 8:28







if you are bundling viperHTML instead of hyperHTML of course it's larger, it has NodeJS stuff that has nothing to do with hyperHTML or lit-html itself. Try again with hyperHTML, in case that wasn't a typo, for surely better results.

– Andrea Giammarchi
Dec 5 '18 at 8:28















I meant to say hyper not viper. I installed it like this: npm install hyperhtml --save.

– Lonnie Best
Dec 6 '18 at 11:12





I meant to say hyper not viper. I installed it like this: npm install hyperhtml --save.

– Lonnie Best
Dec 6 '18 at 11:12












1 Answer
1






active

oldest

votes


















10














This question is a decent summary of what's wrong these days with Web development, so I've decided to take the bullet with this answer, providing also various details needed to answer all the sub-questions of the OP.



Dependencies just because ?




I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size




To produce best results in software, we usually decide to include some dependency because of its features, what it solves for us, and ultimately how well.



The fact people say that one library or utility is small, shouldn't automatically translate into "then I'll include it", specially when your last statement is:




I can live without lit-html




Since I don't feel much effort or even enthusiasm in your question or will to use lit-html, are you sure you even need it at all?



A wrongly measured trade-off



When we talk about "Web things", we usually talk about production code, and all common-sense techniques and best practices used to obtain such production code.



That includes the usage of static files compression, so that by default, importing just render and html from lit-html will produce a bundle of 3.5Kb as minified and compressed production size.



That is where your numbers come from, even if slightly bigger than its first release where the basics worked indeed in about 2Kb (minified and gzipped), lit-html provides already enough juice out of 3.5Kb, which size is absolutely irrelevant compared to the rest of the World Wide Web.



Your favicon.ico, or the request to get it, carrying all the eventual cookies, might weight already a similar, if not greater, amount of bytes.



Are you sure the issue of the internet, or even your site, is a library that adds 3.5Kb extra?



The mobile oriented budget suggested by major experts is less than 170Kb, minified and compressed, which is roughly 48 times lit-html, I think that's enough room for your initial logic.



About criticizing the license




Additionally, the final dist package had this embedded in it 7 times:




Not only compression makes repeated text size almost irrelevant, you are arguing about license text from a Google product that, if I were you, I'd be careful hiding by any mean.




I thought webpack 4 was suppose to remove comments automatically.




When comments are written like /*! important */ these are usually preserved by minifiers, because the author of the source code meant to leave that comment in.



This is a common technique to keep licenses around, but even if there are tools that won't care about any sort of comment, unless instructed differently, as example via --comments=/^!/ via uglify-js, remember that your site, app, project, that is using third parts software, must include such software license in a way or another.



I am confident you didn't mean to discredit the Polymer team or Google license, but since this matter is very delicate, I've thought it was better to be sure we're all on the same page about those.



How to minimize, anyway




How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?




By default, Webpack preserves important comments and unless you want to hook yourself into Webpack internals to avoid doing that by default, you can use one of those tools that won't keep them, unless instructed differently.



The most common used one is UglifyJS. Known as uglify-js npm module, or uglify-es for ES2015+ code, it strips by default all comments.



You can try it via npx without even installing it:



npx uglify-es webpack/exported/lit-html.js


And see that the output will already show no comments.



The way to automate this is to install UglifyJS as devDependency, and modify webpack files directly or through the -o directive, as entry of your package.json script.



Alternatives



It's very easy to integrate UglifyJS in both Webpack and Rollup, but since you already know Webpack, I suggest you take a look at this repository which only aim is to show how to bundle either lit-html or hyperHTML.



You can clone, install, and test it locally, to see best results, dropping eventually the babel transformation if you are targeting ES2015 capable browsers already (it produces smaller results).



You can verify live that once minified and gzipped, including the "Hello World" code, lit-html weights 3.5Kb in Webpack, and 4.2Kb in rollup but after being transpiled with the whole preset-env, something you can also adjust to fine-tune your bundle.



As summary



Even if I'm the author of the main library that competes with lit-html, it's extremely demotivating to read complains about libraries under 10Kb that revolutionize the way we can develop the Web.



Every other mainstream framework is 5 to 20 times heavier than lit, or hyperHTML, and the Web has bigger issues than ~5K utilities so please, next time you see a license for a library that interests you, and the size is irrelevant for everything that is the Web these days, don't easily shoot at the library authors or the bundler that is simply respecting the library copy-rights and licenses.



Thank You.






share|improve this answer
























  • My main complaint is the fact that the lit-html license repeated itself 7 times in the final production file (I guess once for each sub-module that makes up lit-html). Licenses at most should show once in a single file. More is unnecessary redundancy, given that including it once is all that is necessary for compliance.

    – Lonnie Best
    Dec 6 '18 at 11:16






  • 1





    then you should complain with the tool you are using which is incapable of grouping same licenses in one place. However, like I've said already, repeated text means nearly 0 overhead when compression is in place, so that 7 times the license counts pretty much like one time only, that's the reason everyone must serve text files compressed. You have taken 13K as metric that is wrong, because Webpack doesn't tell you the compression version of that output, which is 3.4K indeed.

    – Andrea Giammarchi
    Dec 7 '18 at 6:48











  • Fair enough. I've decided not to use either library. My own methodology is more performant, and this is due to the fact that both libraries unnecessarily re-evaluate each interpolation each time the template is updated. See here.

    – Lonnie Best
    Dec 7 '18 at 11:53











  • This is another misunderstanding. You linked at one example with a comment: hyperHTML does much more. No interpolation is re-evaluated if it's the same value, and all performance test shows this. However, if you believe you don't need any abstraction, that's OK, go ahead.

    – Andrea Giammarchi
    Dec 9 '18 at 0:59













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476595%2fhow-to-minify-lit-html-including-comments%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









10














This question is a decent summary of what's wrong these days with Web development, so I've decided to take the bullet with this answer, providing also various details needed to answer all the sub-questions of the OP.



Dependencies just because ?




I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size




To produce best results in software, we usually decide to include some dependency because of its features, what it solves for us, and ultimately how well.



The fact people say that one library or utility is small, shouldn't automatically translate into "then I'll include it", specially when your last statement is:




I can live without lit-html




Since I don't feel much effort or even enthusiasm in your question or will to use lit-html, are you sure you even need it at all?



A wrongly measured trade-off



When we talk about "Web things", we usually talk about production code, and all common-sense techniques and best practices used to obtain such production code.



That includes the usage of static files compression, so that by default, importing just render and html from lit-html will produce a bundle of 3.5Kb as minified and compressed production size.



That is where your numbers come from, even if slightly bigger than its first release where the basics worked indeed in about 2Kb (minified and gzipped), lit-html provides already enough juice out of 3.5Kb, which size is absolutely irrelevant compared to the rest of the World Wide Web.



Your favicon.ico, or the request to get it, carrying all the eventual cookies, might weight already a similar, if not greater, amount of bytes.



Are you sure the issue of the internet, or even your site, is a library that adds 3.5Kb extra?



The mobile oriented budget suggested by major experts is less than 170Kb, minified and compressed, which is roughly 48 times lit-html, I think that's enough room for your initial logic.



About criticizing the license




Additionally, the final dist package had this embedded in it 7 times:




Not only compression makes repeated text size almost irrelevant, you are arguing about license text from a Google product that, if I were you, I'd be careful hiding by any mean.




I thought webpack 4 was suppose to remove comments automatically.




When comments are written like /*! important */ these are usually preserved by minifiers, because the author of the source code meant to leave that comment in.



This is a common technique to keep licenses around, but even if there are tools that won't care about any sort of comment, unless instructed differently, as example via --comments=/^!/ via uglify-js, remember that your site, app, project, that is using third parts software, must include such software license in a way or another.



I am confident you didn't mean to discredit the Polymer team or Google license, but since this matter is very delicate, I've thought it was better to be sure we're all on the same page about those.



How to minimize, anyway




How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?




By default, Webpack preserves important comments and unless you want to hook yourself into Webpack internals to avoid doing that by default, you can use one of those tools that won't keep them, unless instructed differently.



The most common used one is UglifyJS. Known as uglify-js npm module, or uglify-es for ES2015+ code, it strips by default all comments.



You can try it via npx without even installing it:



npx uglify-es webpack/exported/lit-html.js


And see that the output will already show no comments.



The way to automate this is to install UglifyJS as devDependency, and modify webpack files directly or through the -o directive, as entry of your package.json script.



Alternatives



It's very easy to integrate UglifyJS in both Webpack and Rollup, but since you already know Webpack, I suggest you take a look at this repository which only aim is to show how to bundle either lit-html or hyperHTML.



You can clone, install, and test it locally, to see best results, dropping eventually the babel transformation if you are targeting ES2015 capable browsers already (it produces smaller results).



You can verify live that once minified and gzipped, including the "Hello World" code, lit-html weights 3.5Kb in Webpack, and 4.2Kb in rollup but after being transpiled with the whole preset-env, something you can also adjust to fine-tune your bundle.



As summary



Even if I'm the author of the main library that competes with lit-html, it's extremely demotivating to read complains about libraries under 10Kb that revolutionize the way we can develop the Web.



Every other mainstream framework is 5 to 20 times heavier than lit, or hyperHTML, and the Web has bigger issues than ~5K utilities so please, next time you see a license for a library that interests you, and the size is irrelevant for everything that is the Web these days, don't easily shoot at the library authors or the bundler that is simply respecting the library copy-rights and licenses.



Thank You.






share|improve this answer
























  • My main complaint is the fact that the lit-html license repeated itself 7 times in the final production file (I guess once for each sub-module that makes up lit-html). Licenses at most should show once in a single file. More is unnecessary redundancy, given that including it once is all that is necessary for compliance.

    – Lonnie Best
    Dec 6 '18 at 11:16






  • 1





    then you should complain with the tool you are using which is incapable of grouping same licenses in one place. However, like I've said already, repeated text means nearly 0 overhead when compression is in place, so that 7 times the license counts pretty much like one time only, that's the reason everyone must serve text files compressed. You have taken 13K as metric that is wrong, because Webpack doesn't tell you the compression version of that output, which is 3.4K indeed.

    – Andrea Giammarchi
    Dec 7 '18 at 6:48











  • Fair enough. I've decided not to use either library. My own methodology is more performant, and this is due to the fact that both libraries unnecessarily re-evaluate each interpolation each time the template is updated. See here.

    – Lonnie Best
    Dec 7 '18 at 11:53











  • This is another misunderstanding. You linked at one example with a comment: hyperHTML does much more. No interpolation is re-evaluated if it's the same value, and all performance test shows this. However, if you believe you don't need any abstraction, that's OK, go ahead.

    – Andrea Giammarchi
    Dec 9 '18 at 0:59


















10














This question is a decent summary of what's wrong these days with Web development, so I've decided to take the bullet with this answer, providing also various details needed to answer all the sub-questions of the OP.



Dependencies just because ?




I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size




To produce best results in software, we usually decide to include some dependency because of its features, what it solves for us, and ultimately how well.



The fact people say that one library or utility is small, shouldn't automatically translate into "then I'll include it", specially when your last statement is:




I can live without lit-html




Since I don't feel much effort or even enthusiasm in your question or will to use lit-html, are you sure you even need it at all?



A wrongly measured trade-off



When we talk about "Web things", we usually talk about production code, and all common-sense techniques and best practices used to obtain such production code.



That includes the usage of static files compression, so that by default, importing just render and html from lit-html will produce a bundle of 3.5Kb as minified and compressed production size.



That is where your numbers come from, even if slightly bigger than its first release where the basics worked indeed in about 2Kb (minified and gzipped), lit-html provides already enough juice out of 3.5Kb, which size is absolutely irrelevant compared to the rest of the World Wide Web.



Your favicon.ico, or the request to get it, carrying all the eventual cookies, might weight already a similar, if not greater, amount of bytes.



Are you sure the issue of the internet, or even your site, is a library that adds 3.5Kb extra?



The mobile oriented budget suggested by major experts is less than 170Kb, minified and compressed, which is roughly 48 times lit-html, I think that's enough room for your initial logic.



About criticizing the license




Additionally, the final dist package had this embedded in it 7 times:




Not only compression makes repeated text size almost irrelevant, you are arguing about license text from a Google product that, if I were you, I'd be careful hiding by any mean.




I thought webpack 4 was suppose to remove comments automatically.




When comments are written like /*! important */ these are usually preserved by minifiers, because the author of the source code meant to leave that comment in.



This is a common technique to keep licenses around, but even if there are tools that won't care about any sort of comment, unless instructed differently, as example via --comments=/^!/ via uglify-js, remember that your site, app, project, that is using third parts software, must include such software license in a way or another.



I am confident you didn't mean to discredit the Polymer team or Google license, but since this matter is very delicate, I've thought it was better to be sure we're all on the same page about those.



How to minimize, anyway




How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?




By default, Webpack preserves important comments and unless you want to hook yourself into Webpack internals to avoid doing that by default, you can use one of those tools that won't keep them, unless instructed differently.



The most common used one is UglifyJS. Known as uglify-js npm module, or uglify-es for ES2015+ code, it strips by default all comments.



You can try it via npx without even installing it:



npx uglify-es webpack/exported/lit-html.js


And see that the output will already show no comments.



The way to automate this is to install UglifyJS as devDependency, and modify webpack files directly or through the -o directive, as entry of your package.json script.



Alternatives



It's very easy to integrate UglifyJS in both Webpack and Rollup, but since you already know Webpack, I suggest you take a look at this repository which only aim is to show how to bundle either lit-html or hyperHTML.



You can clone, install, and test it locally, to see best results, dropping eventually the babel transformation if you are targeting ES2015 capable browsers already (it produces smaller results).



You can verify live that once minified and gzipped, including the "Hello World" code, lit-html weights 3.5Kb in Webpack, and 4.2Kb in rollup but after being transpiled with the whole preset-env, something you can also adjust to fine-tune your bundle.



As summary



Even if I'm the author of the main library that competes with lit-html, it's extremely demotivating to read complains about libraries under 10Kb that revolutionize the way we can develop the Web.



Every other mainstream framework is 5 to 20 times heavier than lit, or hyperHTML, and the Web has bigger issues than ~5K utilities so please, next time you see a license for a library that interests you, and the size is irrelevant for everything that is the Web these days, don't easily shoot at the library authors or the bundler that is simply respecting the library copy-rights and licenses.



Thank You.






share|improve this answer
























  • My main complaint is the fact that the lit-html license repeated itself 7 times in the final production file (I guess once for each sub-module that makes up lit-html). Licenses at most should show once in a single file. More is unnecessary redundancy, given that including it once is all that is necessary for compliance.

    – Lonnie Best
    Dec 6 '18 at 11:16






  • 1





    then you should complain with the tool you are using which is incapable of grouping same licenses in one place. However, like I've said already, repeated text means nearly 0 overhead when compression is in place, so that 7 times the license counts pretty much like one time only, that's the reason everyone must serve text files compressed. You have taken 13K as metric that is wrong, because Webpack doesn't tell you the compression version of that output, which is 3.4K indeed.

    – Andrea Giammarchi
    Dec 7 '18 at 6:48











  • Fair enough. I've decided not to use either library. My own methodology is more performant, and this is due to the fact that both libraries unnecessarily re-evaluate each interpolation each time the template is updated. See here.

    – Lonnie Best
    Dec 7 '18 at 11:53











  • This is another misunderstanding. You linked at one example with a comment: hyperHTML does much more. No interpolation is re-evaluated if it's the same value, and all performance test shows this. However, if you believe you don't need any abstraction, that's OK, go ahead.

    – Andrea Giammarchi
    Dec 9 '18 at 0:59
















10












10








10







This question is a decent summary of what's wrong these days with Web development, so I've decided to take the bullet with this answer, providing also various details needed to answer all the sub-questions of the OP.



Dependencies just because ?




I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size




To produce best results in software, we usually decide to include some dependency because of its features, what it solves for us, and ultimately how well.



The fact people say that one library or utility is small, shouldn't automatically translate into "then I'll include it", specially when your last statement is:




I can live without lit-html




Since I don't feel much effort or even enthusiasm in your question or will to use lit-html, are you sure you even need it at all?



A wrongly measured trade-off



When we talk about "Web things", we usually talk about production code, and all common-sense techniques and best practices used to obtain such production code.



That includes the usage of static files compression, so that by default, importing just render and html from lit-html will produce a bundle of 3.5Kb as minified and compressed production size.



That is where your numbers come from, even if slightly bigger than its first release where the basics worked indeed in about 2Kb (minified and gzipped), lit-html provides already enough juice out of 3.5Kb, which size is absolutely irrelevant compared to the rest of the World Wide Web.



Your favicon.ico, or the request to get it, carrying all the eventual cookies, might weight already a similar, if not greater, amount of bytes.



Are you sure the issue of the internet, or even your site, is a library that adds 3.5Kb extra?



The mobile oriented budget suggested by major experts is less than 170Kb, minified and compressed, which is roughly 48 times lit-html, I think that's enough room for your initial logic.



About criticizing the license




Additionally, the final dist package had this embedded in it 7 times:




Not only compression makes repeated text size almost irrelevant, you are arguing about license text from a Google product that, if I were you, I'd be careful hiding by any mean.




I thought webpack 4 was suppose to remove comments automatically.




When comments are written like /*! important */ these are usually preserved by minifiers, because the author of the source code meant to leave that comment in.



This is a common technique to keep licenses around, but even if there are tools that won't care about any sort of comment, unless instructed differently, as example via --comments=/^!/ via uglify-js, remember that your site, app, project, that is using third parts software, must include such software license in a way or another.



I am confident you didn't mean to discredit the Polymer team or Google license, but since this matter is very delicate, I've thought it was better to be sure we're all on the same page about those.



How to minimize, anyway




How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?




By default, Webpack preserves important comments and unless you want to hook yourself into Webpack internals to avoid doing that by default, you can use one of those tools that won't keep them, unless instructed differently.



The most common used one is UglifyJS. Known as uglify-js npm module, or uglify-es for ES2015+ code, it strips by default all comments.



You can try it via npx without even installing it:



npx uglify-es webpack/exported/lit-html.js


And see that the output will already show no comments.



The way to automate this is to install UglifyJS as devDependency, and modify webpack files directly or through the -o directive, as entry of your package.json script.



Alternatives



It's very easy to integrate UglifyJS in both Webpack and Rollup, but since you already know Webpack, I suggest you take a look at this repository which only aim is to show how to bundle either lit-html or hyperHTML.



You can clone, install, and test it locally, to see best results, dropping eventually the babel transformation if you are targeting ES2015 capable browsers already (it produces smaller results).



You can verify live that once minified and gzipped, including the "Hello World" code, lit-html weights 3.5Kb in Webpack, and 4.2Kb in rollup but after being transpiled with the whole preset-env, something you can also adjust to fine-tune your bundle.



As summary



Even if I'm the author of the main library that competes with lit-html, it's extremely demotivating to read complains about libraries under 10Kb that revolutionize the way we can develop the Web.



Every other mainstream framework is 5 to 20 times heavier than lit, or hyperHTML, and the Web has bigger issues than ~5K utilities so please, next time you see a license for a library that interests you, and the size is irrelevant for everything that is the Web these days, don't easily shoot at the library authors or the bundler that is simply respecting the library copy-rights and licenses.



Thank You.






share|improve this answer













This question is a decent summary of what's wrong these days with Web development, so I've decided to take the bullet with this answer, providing also various details needed to answer all the sub-questions of the OP.



Dependencies just because ?




I've heard numerous times (from various sources) that lit-html is only 2 or 3KB in size




To produce best results in software, we usually decide to include some dependency because of its features, what it solves for us, and ultimately how well.



The fact people say that one library or utility is small, shouldn't automatically translate into "then I'll include it", specially when your last statement is:




I can live without lit-html




Since I don't feel much effort or even enthusiasm in your question or will to use lit-html, are you sure you even need it at all?



A wrongly measured trade-off



When we talk about "Web things", we usually talk about production code, and all common-sense techniques and best practices used to obtain such production code.



That includes the usage of static files compression, so that by default, importing just render and html from lit-html will produce a bundle of 3.5Kb as minified and compressed production size.



That is where your numbers come from, even if slightly bigger than its first release where the basics worked indeed in about 2Kb (minified and gzipped), lit-html provides already enough juice out of 3.5Kb, which size is absolutely irrelevant compared to the rest of the World Wide Web.



Your favicon.ico, or the request to get it, carrying all the eventual cookies, might weight already a similar, if not greater, amount of bytes.



Are you sure the issue of the internet, or even your site, is a library that adds 3.5Kb extra?



The mobile oriented budget suggested by major experts is less than 170Kb, minified and compressed, which is roughly 48 times lit-html, I think that's enough room for your initial logic.



About criticizing the license




Additionally, the final dist package had this embedded in it 7 times:




Not only compression makes repeated text size almost irrelevant, you are arguing about license text from a Google product that, if I were you, I'd be careful hiding by any mean.




I thought webpack 4 was suppose to remove comments automatically.




When comments are written like /*! important */ these are usually preserved by minifiers, because the author of the source code meant to leave that comment in.



This is a common technique to keep licenses around, but even if there are tools that won't care about any sort of comment, unless instructed differently, as example via --comments=/^!/ via uglify-js, remember that your site, app, project, that is using third parts software, must include such software license in a way or another.



I am confident you didn't mean to discredit the Polymer team or Google license, but since this matter is very delicate, I've thought it was better to be sure we're all on the same page about those.



How to minimize, anyway




How can I get this to be tightly minimized with all my other code (where comments are automatically removed and everything is just pushed together in one line)?




By default, Webpack preserves important comments and unless you want to hook yourself into Webpack internals to avoid doing that by default, you can use one of those tools that won't keep them, unless instructed differently.



The most common used one is UglifyJS. Known as uglify-js npm module, or uglify-es for ES2015+ code, it strips by default all comments.



You can try it via npx without even installing it:



npx uglify-es webpack/exported/lit-html.js


And see that the output will already show no comments.



The way to automate this is to install UglifyJS as devDependency, and modify webpack files directly or through the -o directive, as entry of your package.json script.



Alternatives



It's very easy to integrate UglifyJS in both Webpack and Rollup, but since you already know Webpack, I suggest you take a look at this repository which only aim is to show how to bundle either lit-html or hyperHTML.



You can clone, install, and test it locally, to see best results, dropping eventually the babel transformation if you are targeting ES2015 capable browsers already (it produces smaller results).



You can verify live that once minified and gzipped, including the "Hello World" code, lit-html weights 3.5Kb in Webpack, and 4.2Kb in rollup but after being transpiled with the whole preset-env, something you can also adjust to fine-tune your bundle.



As summary



Even if I'm the author of the main library that competes with lit-html, it's extremely demotivating to read complains about libraries under 10Kb that revolutionize the way we can develop the Web.



Every other mainstream framework is 5 to 20 times heavier than lit, or hyperHTML, and the Web has bigger issues than ~5K utilities so please, next time you see a license for a library that interests you, and the size is irrelevant for everything that is the Web these days, don't easily shoot at the library authors or the bundler that is simply respecting the library copy-rights and licenses.



Thank You.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 5 '18 at 11:06









Andrea GiammarchiAndrea Giammarchi

1,388711




1,388711













  • My main complaint is the fact that the lit-html license repeated itself 7 times in the final production file (I guess once for each sub-module that makes up lit-html). Licenses at most should show once in a single file. More is unnecessary redundancy, given that including it once is all that is necessary for compliance.

    – Lonnie Best
    Dec 6 '18 at 11:16






  • 1





    then you should complain with the tool you are using which is incapable of grouping same licenses in one place. However, like I've said already, repeated text means nearly 0 overhead when compression is in place, so that 7 times the license counts pretty much like one time only, that's the reason everyone must serve text files compressed. You have taken 13K as metric that is wrong, because Webpack doesn't tell you the compression version of that output, which is 3.4K indeed.

    – Andrea Giammarchi
    Dec 7 '18 at 6:48











  • Fair enough. I've decided not to use either library. My own methodology is more performant, and this is due to the fact that both libraries unnecessarily re-evaluate each interpolation each time the template is updated. See here.

    – Lonnie Best
    Dec 7 '18 at 11:53











  • This is another misunderstanding. You linked at one example with a comment: hyperHTML does much more. No interpolation is re-evaluated if it's the same value, and all performance test shows this. However, if you believe you don't need any abstraction, that's OK, go ahead.

    – Andrea Giammarchi
    Dec 9 '18 at 0:59





















  • My main complaint is the fact that the lit-html license repeated itself 7 times in the final production file (I guess once for each sub-module that makes up lit-html). Licenses at most should show once in a single file. More is unnecessary redundancy, given that including it once is all that is necessary for compliance.

    – Lonnie Best
    Dec 6 '18 at 11:16






  • 1





    then you should complain with the tool you are using which is incapable of grouping same licenses in one place. However, like I've said already, repeated text means nearly 0 overhead when compression is in place, so that 7 times the license counts pretty much like one time only, that's the reason everyone must serve text files compressed. You have taken 13K as metric that is wrong, because Webpack doesn't tell you the compression version of that output, which is 3.4K indeed.

    – Andrea Giammarchi
    Dec 7 '18 at 6:48











  • Fair enough. I've decided not to use either library. My own methodology is more performant, and this is due to the fact that both libraries unnecessarily re-evaluate each interpolation each time the template is updated. See here.

    – Lonnie Best
    Dec 7 '18 at 11:53











  • This is another misunderstanding. You linked at one example with a comment: hyperHTML does much more. No interpolation is re-evaluated if it's the same value, and all performance test shows this. However, if you believe you don't need any abstraction, that's OK, go ahead.

    – Andrea Giammarchi
    Dec 9 '18 at 0:59



















My main complaint is the fact that the lit-html license repeated itself 7 times in the final production file (I guess once for each sub-module that makes up lit-html). Licenses at most should show once in a single file. More is unnecessary redundancy, given that including it once is all that is necessary for compliance.

– Lonnie Best
Dec 6 '18 at 11:16





My main complaint is the fact that the lit-html license repeated itself 7 times in the final production file (I guess once for each sub-module that makes up lit-html). Licenses at most should show once in a single file. More is unnecessary redundancy, given that including it once is all that is necessary for compliance.

– Lonnie Best
Dec 6 '18 at 11:16




1




1





then you should complain with the tool you are using which is incapable of grouping same licenses in one place. However, like I've said already, repeated text means nearly 0 overhead when compression is in place, so that 7 times the license counts pretty much like one time only, that's the reason everyone must serve text files compressed. You have taken 13K as metric that is wrong, because Webpack doesn't tell you the compression version of that output, which is 3.4K indeed.

– Andrea Giammarchi
Dec 7 '18 at 6:48





then you should complain with the tool you are using which is incapable of grouping same licenses in one place. However, like I've said already, repeated text means nearly 0 overhead when compression is in place, so that 7 times the license counts pretty much like one time only, that's the reason everyone must serve text files compressed. You have taken 13K as metric that is wrong, because Webpack doesn't tell you the compression version of that output, which is 3.4K indeed.

– Andrea Giammarchi
Dec 7 '18 at 6:48













Fair enough. I've decided not to use either library. My own methodology is more performant, and this is due to the fact that both libraries unnecessarily re-evaluate each interpolation each time the template is updated. See here.

– Lonnie Best
Dec 7 '18 at 11:53





Fair enough. I've decided not to use either library. My own methodology is more performant, and this is due to the fact that both libraries unnecessarily re-evaluate each interpolation each time the template is updated. See here.

– Lonnie Best
Dec 7 '18 at 11:53













This is another misunderstanding. You linked at one example with a comment: hyperHTML does much more. No interpolation is re-evaluated if it's the same value, and all performance test shows this. However, if you believe you don't need any abstraction, that's OK, go ahead.

– Andrea Giammarchi
Dec 9 '18 at 0:59







This is another misunderstanding. You linked at one example with a comment: hyperHTML does much more. No interpolation is re-evaluated if it's the same value, and all performance test shows this. However, if you believe you don't need any abstraction, that's OK, go ahead.

– Andrea Giammarchi
Dec 9 '18 at 0:59






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476595%2fhow-to-minify-lit-html-including-comments%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga