简体   繁体   English

关于YUI压缩器和JavaScript

[英]About YUI compressor and javascripts

I am using handlebars in my website. 我在网站上使用把手。 So that I need to send the 'handlebars.runtime.js' to the client side. 因此,我需要将“ handlebars.runtime.js”发送到客户端。 However I found that the 'handlebars.runtime.js' from the offocial website isn't compressed, so I use the YUI compressor to compress it. 但是我发现来自官方网站的'handlebars.runtime.js'没有被压缩,因此我使用YUI压缩器对其进行压缩。

Something weird occurred when I checked the compressed 'handlebars.runtime.js': some codes are disappeared in the compressed one when I compared to the previous one. 当我检查压缩的“ handlebars.runtime.js”时,发生了一些奇怪的事情:当与上一个代码比较时,压缩的代码中有些代码消失了。 And the very beginning of the compressed one is like this: 压缩文件的开头是这样的:

/*!

 handlebars v1.3.0

 Copyright (C) 2011 by Yehuda Katz

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.

 @license
 */
;var Handlebars=(function(){v (rest of the codes...)

As you can see, the comments are not deleted by the YUI compressor and there is a weird semicolon at the very beginning of the codes. 如您所见,YUI压缩器不会删除注释,并且在代码的开头有一个奇怪的分号。 Can anyone explain this? 谁能解释一下? Thanks! 谢谢!

PS: the beginning uncompressed 'handlebars.runtime.js' is like this: PS:开头的未压缩的“ handlebars.runtime.js”是这样的:

/*!

handlebars v1.3.0

Copyright (C) 2011 by Yehuda Katz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@license
*/
/* exported Handlebars */
var Handlebars = (function() {
// handlebars/safe-string.js
var __module3__ = (function() {
"use strict";
var __exports__;
// Build out our basic SafeString type
function SafeString(string) {
this.string = string;
}

 SafeString.prototype.toString = function() {
  return "" + this.string;
 };

  __exports__ = SafeString;
  return __exports__;
})();

It's still present because of the exclamation mark in the starting comment /*! 由于开始注释/*!带有感叹号,因此它仍然存在/*!

This is intended, as usually when using open source library, you want to preserve the copyright notes 通常,这是在使用开放源代码库时要保留的版权说明。

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

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