question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minifying the resulting JS file more

See original GitHub issue

Hi, I just saw that in the resulting JS file there are a lot of white spaces, many of them probably unecessary, wasting bandwidth, and every KB saved is a great thing! Doesn’t sound like much, but still…

I searched for “at least” double spaces in VSCode and then deleted them to compare the sizes.

Before:

After:

Please note that this might not be 100% accurate, nor have I tested the code for functionality, but most of these spaces could be eliminated without any issue, especially those between html tags, before/after line breaks \n) and such.

I’m not just pointing it out. I want to help too. That means if I’m allowed I would clone this repo and include a little grunt script into it. This script would essentially take the final JS file, erase the spaces following a regex or something and then overwrite it. There are probably other ways, but I was thinking that this would be the straightest route.

EDIT: I just saw that ESLint has some minifying options too, but I’m not familiar with it, I just flown over the related documentation real quick.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Fusseldiebcommented, Aug 26, 2020

Terser has a rollup plugin so if that does the trick I’m all for it 👍

I used it according to documentation, but for some reason it just removed the comments from the final file, leaving the JS file with all whitespaces in place, making it even bigger. I tried all available options, but they shouldn’t be needed, since mangle and compress is already enabled by “default” by terser and this is just a wrapper. I thought a plugin was interfering with it, so I disabled everything and tried to rollup-plugin-terser almost barebone, to no avail.

Testing Terser itself in the CLI did in fact minimize the final file and made it 543 Bytes smaller (by basically making \" into " where possible) compared to babels “minify”. However, the whitespaces after \n on the HTML Elements are still there.

Am currently trying to make use of the more “advanced” options of the Terser CLI… Let’s see…

EDIT: Using Terser and using almost all its compress functions (ES6), I managed to reduce it 2604 Bytes compared to master dist. Not yet tested. Whitespaces in template literals are still there.

EDIT2: RTFM they say, and it’s true. According to lit-htmls documentation I found rollup-plugin-minify-html-literals and that did the trick right away. Whitespaces gone. Size reduced even further. Now 7478 Bytes (7KB!!!) less compared to master dist.

EDIT3: Tested in “production” Home Assistant with several graph styles (y-secondary, bars, simple, state_map…) and working fine. Filesize currently: 80.8KB.

Can I PR it, @kalkih ?

0reactions
stale[bot]commented, Feb 7, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this is still an active issue, please let us know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Minify JavaScript — Recommended Tools and Methods
It's nearly impossible to minify all of the codes in large JavaScript files manually. Manually minifying JavaScript files is only possible for ...
Read more >
What is Minification | Why minify JS, HTML, CSS files - Imperva
Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used...
Read more >
How to organize minification and packaging of css and js files ...
It can compress JavaScript as well as CSS. Just run it for all your files, then concatenate them into one 'package' file.
Read more >
Minify JavaScript | GTmetrix
Minification makes your code leaner and more compact by removing unnecessary elements, decreasing the file size, reducing the bandwidth consumed, and speeding ...
Read more >
How to Minify JavaScript & CSS? - Code Institute Global
Minifying a CSS file entails removing extraneous characters from the source code in order to minimise file size and speed up site loading....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found