Care about your users, don't minify your JavaScript
framatube.org
framatube.org
Compression is not a replacement for minification. The client still needs to parse and run the uncompressed source code. Minification provides measurable performance gains for clients by reducing parse times and p̴o̴t̴e̴n̴t̴i̴a̴l̴l̴y̴ ̴e̴v̴e̴n̴ ̴a̴l̴l̴o̴w̴i̴n̴g̴ ̴f̴u̴n̴c̴t̴i̴o̴n̴s̴ ̴t̴o̴ ̴b̴e̴c̴o̴m̴e̴ ̴s̴m̴a̴l̴l̴ ̴e̴n̴o̴u̴g̴h̴ ̴t̴h̴a̴t̴ ̴t̴h̴e̴y̴ ̴c̴a̴n̴ ̴b̴e̴ ̴i̴n̴l̴i̴n̴e̴d̴ (the inclining part is not true anymore; see child comment).
Licence retention isn't a reason to skip minification either. Practically every modern minified retains licence comments.
And finally, your users can still read the original source code if you ship source maps.
Care about your users, please minify your JavaScript :)
That sounds like an omission from the talk indeed, assuming the gains are indeed noticeable and not just theoretically measurable. Do you have some numbers for this, or a link to some?
Apparently, that's no longer the case, at least in V8[0]
Parse times however are indeed a real concern and start to matter a lot as you go down the list of mobile hardware and their performance. This graph[1] shows parse times for a 1MB bundle of JavaScript in various devices.
[0] https://github.com/v8/v8/commit/0702ea3000df8235c8bfcf1e99a9...
[1] https://miro.medium.com/max/1400/1*dnhO1M_zlmAhvtQY_7tZmA.jp...
[0] https://v8.dev/_img/cost-of-javascript-2019/reddit-js-proces...
But what I really need to know is how you created the strike-through effect on the words in your comment!
(Since I don't see it in the HN format help[0])
Most of the arguments in this short presentation feel disingenuous. Minified versions of most 3rd party libraries are provided directly by the open source maintainers, so minifying your own code and including their minified library isn't violating anything. Companies are under no obligation to provide their own proprietary source code in a readable format with variable names intact.
Somewhere between 99.99% and 100% of users would prefer the faster loading, more responsive site with minified code. I think the authors started with a conclusion they wanted and tried to walk backward until they found some arguments in favor of their conclusion.
You didn't understand what the speaker meant here. The point is (indeed) not that the license states that you must provide a readable format with variable names intact. You can use map files for that or just link the original where they can find the software for themselves. It's this link and notice that people can go out and use it for themselves, the license that you are required to include, that might be stripped by minification.
If the authors provide a minified, unlicensed version themselves, then that is copyrighted and you're not allowed to use it. You don't have a license without a license, so if the minified version doesn't contain a license, then you can't use it. Likely, there is a separate file or page saying what the code is licensed as and that covers the minified version as well. But that doesn't give you a get out of jail free card: that separate license will (almost always) still say that you have to include a copyright notice somewhere. Perhaps not in the minified file itself, but then elsewhere on the site.
For example, from the MIT license:
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The video covered that.
If you want to give your users access to your code, minify (preferably with a minifier that uses newlines where possible) and use source maps.
edit: yay source maps!
[source: I wrote the JSC parsers]
Obviously less non-whitespace data to parse will make the parsing faster, but I would be curious whether it bothers trying to detect dead code. It seems similar to a halting problem, knowing whether something can be reached, but I'm not well-versed enough in that theory to really say much more than this gut feeling.
I recall some minifiers that definitely did - whether they're still in use I don't know (I haven't been working in engine dev for a few years).
For JSC's parsing the most expensive things are strict mode, and certain "errors" which basically trigger a rollback in the parser and then a reparse with more validation.
Minify, include mappings, and you are good to go.
That being said, the most important point the author makes is to ensure that compression is on when you deliver your assets! Whether it be gzip, brotli, or whatever other arcane format, make sure for your users that it is on.
Exactly. There are countless JS-powered sites that for any multitude of reasons don't want it to be easy to extract their code. Ignoring whether or not that's "right" or ethical, those sites are fully within their rights to make it as difficult as possible to duplicate the work that they've put in to create their platform. I would imagine if you asked most C-level and legal teams "is the code on your website something you want people to be able to copy at will?", 95%+ would say they don't want that to be possible, and you might even spur some of them to force their developers to spend time making it _even harder_ to copy.
Unfortunately, the web isn't the free/public/open-source utopia it once was, because a large majority of business takes place online. Sure there are niche sites that still cater to such ideals, but a majority of the population couldn't give a rat's ass if it's easy to copy the JS from Facebook/Amazon/YouTube/etc.
Of course it does also obfuscate to a point where large chunks of code are not easily reusable. You can still easily understand small snippets if you try.
I certainly found it very obscure the one time I had to investigate a minified app, that’s why I asked.
in more seriousness though - please minify, but don't obfuscate, or even better don't use js if it isn't completly necessary
for a more complex web-app/dashboard it's a bit harder to avoid JS
A blog does not. An interactive chat application does.
What's the point of advocating against client-side rendering if the alternative is server-side rendering that only covers some of the features you want?
In general when I see people recreating browser features (like display layout) using JavaScript, they do a strictly worse job of it than what is already built in to the browser. Most JavaScript therefore makes my life worse.
But there are things that can be done which are not possible any other ways. Interactive games, live chats, the scrolling in Google Maps and so on. They can be great. But far too often, they aren't. :-(
Care about all your users: use what you need to use.