JavaScript 라이브러리를 최소화하고 압축하기 위해 무엇을 사용합니까?
JavaScript 라이브러리를 최소화하고 압축하기 위해 무엇을 사용합니까?
YUI Compressor를 사용 합니다. 일을 잘하는 것 같습니다!
나는 YUI Compressor 를 오랫동안 사용해 왔고 아무런 문제가 없었지만 최근에 Google Closure Compiler를 사용하기 시작하여 성공했습니다. 지금까지 내 인상 :
- 일반적으로 파일 크기 감소 측면에서 YUI Compressor를 능가합니다. 단순 모드에서는 소량, 고급 모드에서는 많이.
- 단순 모드는 지금까지 YUI Compressor만큼 안정적이었습니다. 내가 먹인 것은 아무 문제도 보이지 않았습니다.
- 고급 "컴파일"모드는 일부 스크립트에 적합하지만 스크립트의 크기를 크게 줄이면 코드를 깨뜨릴 수있는 적절한 기회를 제공하는 많은 비용이 발생합니다. 이러한 문제 중 일부를 처리하는 방법 이 있고 그것이 무엇을하는지 이해 하면 문제 를 피하는 데 큰 도움이 될 수 있지만 일반적으로이 모드를 사용하지 않습니다.
일반적으로 YUI Compressor를 약간 능가하기 때문에 간단한 "컴파일"모드에서 Google Closure Compiler를 사용하는 것으로 이동했습니다. 나는 YUI Compressor보다 상당히 적게 사용했지만 지금까지 본 것에서 나는 그것을 추천합니다.
아직 시도하지 않았지만 유망하게 들리는 다른 하나는 Mihai Bazon의 UglifyJS 입니다.
여기에 많은 가능성이 있습니다.
- YUI 압축기 다른 답변에서 언급 한,
- 구글 폐쇄 컴파일러 ,
- 도조 툴킷 자신에 의해 사용의 ShrinkSafe 컴파일러 빌드 시스템 ,
- Douglas Crockford 의 여전히 실제 JSMin ,
- 다른 사람들이 언급 한 UglifyJS ,
- 그리고 상용 솔루션 인 javaScript Obfuscator (개인적으로 사용하지 않음)
내 개인적인 경험에 비추어 볼 때 Dojo SDK를 사용하여 사용자 지정 빌드를 빌드 한 다음 일반적인 ShrinkSafe 컴파일러 또는 현재 지원하는 Google Closure를 사용하도록 구성 할 수 있습니다 .
압축 측면에서 Google Closure가 지금까지 나에게 가장 좋은 결과를 내고 있다고 생각하지만 일반적으로 ShrinkSafe에 만족하고 약간 오래되고 견고하지만 Closure Compiler는 블록에서 약간의 새로운 아이처럼 보입니다. (예를 들어 이해 관계자가 너무 좋아하지 않을 수 있음).
어떤 사람들은 YUI 압축기에 의해서만 맹세합니다. 개인적으로 보증 할 수 없습니다.
이제 자신의 JavaScript 코드가 아니라 라이브러리 를 압축하는 것이 문제라면 , 이름을 바꾸거나 제거해서는 안되는 기호를 내보내려면 이러한 도구의 대부분이 필요하기 때문에 분명히 더 복잡해집니다. 대부분의 괜찮은 압축기는 사용하지 않는다고 생각하는 기능 (종종 라이브러리의 경우 프로젝트에 묶여 있지 않은 경우)을 제거하고 이름을 짧게 변경하고 문자를 적게 사용합니다. 또한 분명히 공개를 원하므로 문제가됩니다. 변조되지 않을 API.
이 주제에 대한 다른 스레드도 찾을 수 있으며 도구의 지원 문서에서 정보를 찾을 수 있습니다. 또한 한 번 봐 가지고 할 수 있습니다 JSBuilder2 의 ExtJS를 들어, (그래서, ShrinkSafe 또는 폐쇄 컴파일러를 사용하여) Dojo의 빌드 도구 펜던트의 일종 (유이 압축기를 사용하여).
(죄송합니다. 새로운 SO 사용자이기 때문에 하나 이상의 링크를 추가 할 수 없으므로 도구에 직접 연결할 수 없습니다.)
편집 : 압축이 버그를 유발할 수 있고 코드가 엉망이 아니기 때문에 디버깅을 더 쉽게 만든다는 일부 답변에 표현 된 우려 사항과 관련하여 : 예, 유효한 문제입니다. 하나:
- gzip 압축이 활성화 된 상태에서도 minifier를 사용하면 대역폭 측면에서 상당한 개선을 얻을 수 있습니다 (압축기의 수명을 더 쉽게 만들어 gzip 압축을 활용하는 방법을 배울 수 있습니다).
- 동작이 동일한 지 확인하려면 디버그 및 프로덕션 모드에서 코드를 맛보기 만하면됩니다. 내 말은, 그것은 당신의 일의 일부이기도합니다 ...
- 이러한 압축기 중 일부는 한동안 사용되어 왔으며 실제로 코드에 버그를 유발하지 않습니다. 그들은 정말 그냥 물건을 재구성하고 문자열을 대체하고 있습니다.
- 일부 압축기 (예 : dojo 빌드 시스템)에는 압축 된 출력과 압축되지 않은 출력을 모두 생성 할 수있는 옵션이 함께 제공되므로 예를 들어 쿼리 매개 변수를 사용하여 디버깅 및 프로덕션에 대해 다른 모드를 사용할 수 있습니다.
나는 자바 스크립트를 전혀 최소화하지 않는다. gzip 압축은 나에게 충분하며 오류 메시지가 여전히 유용하다는 추가적인 이점이있다.
나도 YUI Compressor를 사용합니다. 내 프로젝트에서 사용하는 다음과 같은 개미 작업이 있습니다.
<!--
YUI Compressor tasks
http://www.julienlecomte.net/yuicompressor/README
-->
<property name="yuicompressor.jar"
value="C:/devlibs/yuicompressor-2.2.4/build/yuicompressor-2.2.4.jar"/>
<target name="js.compress">
<!-- Create min directory under js direcrtory if it doesnt exist -->
<mkdir dir="${js-directory}/min" />
<apply verbose="true" executable="java" parallel="false" failonerror="true">
<fileset dir="${js-directory}" includes="*.js"/>
<arg line="-jar"/>
<arg path="${yuicompressor.jar}"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.js" to="${js-directory}/min/*-min.js"/>
<targetfile/>
</apply>
</target>
Dean Edward's packer achieves some pretty good compression ratios. It has command line implementations which allows it to be used in a continuous integration process.
UglifyJS is a new one.
UglifyJS compresses better than YUI Compressor and just about on par with the Google Closure Compiler. For example, the compressed version of jQuery from the Google Closure Compiler is only 403 bytes smaller than the version produced by UglifyJS - impressive! UglifyJS is also the fastest to run by a long shot, beating Closure by over 6 seconds!
Additionally, the code produced by UglifyJS is safer than the code that Closure generates. For example, Closure doesn’t know how to deal with eval or with{} - it just logs an error and continues to rename variables anyway. This, obviously, leads to broken code. UglifyJS does not have this problem.
More information can be found here: http://badassjs.com/post/971960912/uglifyjs-a-fast-new-javascript-compressor-for-node-js
Google's closure tools
You can map the minified version to the regular source code for debugging in Firebug with their add-on.
I have tried YUI compressor before, but it gives me error message.
I suggest using JSMIN to minify your javascript:
http://www.crockford.com/javascript/jsmin.html
Here's a solution from Microsoft that you can integrate into Visual Studio to minify the files automatically when you build your project.
To Install:
Download the msi from : http://aspnet.codeplex.com/releases/view/40584
You may need to restart your computer after its finished.
To Use:
Edit your .csproj file and include the following at the end of the file (but before the </Project>
tag):
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
<Target Name="AfterBuild">
<ItemGroup>
<JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
<CSS Include="**\*.css" Exclude="**\*.min.css" />
</ItemGroup>
<AjaxMin
JsSourceFiles="@(JS)"
JsSourceExtensionPattern="\.js$"
JsTargetExtension=".min.js"
CssSourceFiles="@(CSS)"
CssSourceExtensionPattern="\.css$"
CssTargetExtension=".min.css"/>
</Target>
Now when you build your project, all CSS and js files that don't end in .min.js, .min.css will be minified (See the "Exclude" attribute to exclude other files from being minified).
http://code.google.com/p/jsmin-php/
Good old Doug Crockford :-) The beauty of this is that with cache control you can get somelovely automated compression only when it is required. Or in one of my projects I just output the compressed/gzipped files and delete them when I make a change. For a development environment, I just dont' call the minification script.
I use a simple (3-4 line) wrapper script around JavaScript::Minifier::XS.
Here is an article which described how to use YUI Compressor for minimizing files during build: Compressing JS files as part of your build process
I use perl's JavaScript::Minifier. It works pretty well and you can e.g. replace some phrases using perl.
http://caja.appspot.com/tools/index does all three of HTML/CSS/JS.
https://jawr.dev.java.net/ is excellent for minification and versioning
There is a very good online compressor:
http://javascriptcompressor.com/
You can also shrink variables, if you want even more compresed.
Hope it helps
ReferenceURL : https://stackoverflow.com/questions/599911/what-do-you-use-to-minimize-and-compress-javascript-libraries
'developer tip' 카테고리의 다른 글
CSS에서 이미지 위에 오버레이를 만드는 방법은 무엇입니까? (0) | 2021.01.10 |
---|---|
오류 : [ngModel : datefmt]`2015-05-29T19 : 06 : 16.693209Z`가 날짜가 될 것으로 예상 됨-Angular (0) | 2021.01.10 |
Ruby XML to JSON 변환기? (0) | 2021.01.10 |
인증 된 사용자의 역할 저장 / 할당 (0) | 2021.01.10 |
document.getElementById (id) .focus ()가 firefox 또는 chrome에서 작동하지 않습니다. (0) | 2021.01.09 |