简体   繁体   English

做minify和uglify都有意义吗?

[英]Does it make sense to do both minify and uglify?

Given that uglification involves some minification in the process, does it still make sense to do both minify and uglify? 鉴于丑化在这个过程中涉及一些缩小,同时做minify和uglify仍然有意义吗? If yes, should one minify or uglify first? 如果是的话,首先应该缩小还是丑化? Is it enough to do uglify only? 只做uglify就足够了吗? Will the code be more obfuscated if both are done? 如果两者都完成,代码会更加混淆吗?

There is no real distinction between the two. 两者之间没有真正的区别。 Even Uglify calls itself a minification toolkit. 甚至Uglify也称自己为缩小工具包。

The distinction could be more relevant when comparing JS minification to CSS minification - CSS minification involves only removing whitespace - the original code remains intact. 将JS缩小与CSS缩小比较时,区别可能更为相关 - CSS缩小仅涉及删除空格 - 原始代码保持不变。

With JS it is possible to not only remove whitespace, but also to make transformations to the code, such as truncating variable names to single characters. 使用JS,不仅可以删除空格,还可以对代码进行转换,例如将变量名截断为单个字符。

Minifying JavaScript not only makes the source smaller, it also makes the code less readable, or obfuscates it. 缩小JavaScript不仅会缩小源代码,还会降低代码的可读性,或者使代码混淆。 But do not operate under the assumption that minification or uglification, or whatever you want to call it, is a security measure. 但是,不要假设缩小或丑化,或任何你想称之为的安全措施。 It isn't encryption. 它不是加密。 The code is harder to read, but not impossible to read, and while it's not usually possible to return minified code back to its original form, it is possible to 'beautify' it and make it more readable. 代码更难阅读,但并非不可能阅读,虽然通常不可能将缩小的代码恢复为原始形式,但可以“美化”它并使其更具可读性。

It doesn't make sense to both minify and uglify because most minifiers will both remove whitespace and unnecessary characters, as well as obfuscate the code. minify和uglify都没有意义,因为大多数minifiers都会删除空格和不必要的字符,以及混淆代码。 All you're doing is introducing another build step. 你所做的只是引入另一个构建步骤。

Minifying is just removing unnecessary white-space and redundant like comments and semicolons. 缩小只是删除不必要的空白和冗余,如注释和分号。 And it can be reversed back when needed. 它可以在需要时反转。

Uglifying is transforming the code into an "unreadable" form by changing variable names, function names, etc, to hide the original content. Uglifying通过更改变量名称,函数名称等将代码转换为“不可读”的形式,以隐藏原始内容。 Once it is used there's no way to reverse it back. 一旦使用它就无法逆转它。

Some libraries like UglifyJS does minification when used, by removing unnecessary parts. 像UglifyJS这样的库在使用时通过删除不必要的部分来进行缩小。 But in general Uglifying is making the code unreadable. 但总的来说,Uglifying正在使代码难以理解。

Minifying your code speeds up your page loading, making visitors and search engines happy and it is also readable. 缩小代码可加快页面加载速度,使访问者和搜索引擎感到满意并且可读性更高。 Most major browsers minify the code before execution. 大多数主流浏览器在执行前缩小代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM