자주 묻는 질문(FAQ)
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
-
Closure Compiler란 무엇인가요? 사용해야 하는 이유
-
Closure Compiler는 JavaScript 다운로드 및 실행 속도를 높이는 도구입니다. Closure Compiler를 사용하여 JavaScript 파일의 크기를 줄이고 효율성을 높일 수 있습니다.
-
Closure Compiler는 다른 JavaScript 압축기와 어떻게 다른가요?
-
일반적으로 Closure Compiler는 다른 코드 축소 도구의 압축을 충족하거나 초과하며 웹 애플리케이션의 다운로드 시간을 개선합니다. 또한 Closure Compiler를 사용하면 테스트 중에가 아닌 개발 중에 구문 오류를 찾고 잠재적으로 버그가 있는 코드 패턴을 식별할 수 있습니다.
단순 모드에서는 Closure Compiler가 컴파일러와 유사한 분석을 사용하여 코드 크기를 최소화하는 추가 방법을 찾기 때문에 다른 도구보다 더 나은 성능을 발휘할 수 있습니다. 예를 들어 Closure Compiler는 몇 번만 사용되는 함수를 인라인 처리하고, 변수 이름을 재사용하고, 상수 표현식을 사전 계산할 수 있습니다.
고급 모드에서 Closure Compiler는 추가된 유형 주석을 사용하여 발견하기 어려운 버그를 찾을 수도 있습니다.
-
Closure Compiler가 HTML에 삽입된 JavaScript를 컴파일할 수 있나요?
-
아니요. Closure Compiler는 JavaScript만 포함된 파일에서만 작동합니다.
-
Closure Compiler를 다른 JavaScript 축소 도구와 함께 사용할 수 있나요?
-
예. Closure Compiler는 유효한 JavaScript를 읽어 유효한 JavaScript를 생성하므로 다른 축소 도구를 통해 파일을 실행하기 전이나 후에 JavaScript 파일에 Closure Compiler를 적용할 수 있습니다.
Closure Compiler 및 기타 축소 도구는 수신 코드에 관한 기대치가 있을 수 있습니다. 주석을 삭제하는 축소기는 다른 도구에 필요한 라이선스나 주석 정보를 삭제할 수 있습니다.
-
Closure Compiler에서 생성된 JavaScript를 디버그하려면 어떻게 해야 하나요?
-
컴파일된 코드에서 오류가 발생하거나 예상치 못한 동작이 나타나는 경우 소스 맵을 사용하여 문제를 디버그할 수 있습니다. 소스 맵은 컴파일된 코드와 원본 소스 코드 간의 매핑을 제공하므로 브라우저의 개발자 도구에서 컴파일된 코드 대신 원본 소스 코드를 표시할 수 있습니다.
Closure Compiler가 소스 맵을 생성하도록 하려면 명령줄에서
--create_source_map
플래그를 전달하세요. 예를 들면 다음과 같습니다.
$ java -jar compiler.jar --js example.js --create_source_map ./example-map --js_output_file example-compiled.js
그런 다음 소스 맵을 지원하는 브라우저 (예: Chrome 또는 Firefox)를 사용하는 경우 컴파일되지 않은 코드와 마찬가지로 중단점을 설정할 수 있으며 브라우저의 개발자 도구에 원본 소스의 해당 코드 줄이 표시됩니다. 소스 맵에 관한 정보를 비롯한 Chrome 개발자 도구에 관한 자세한 내용은 JavaScript 디버깅을 참고하세요.
-
컴파일러가 애플리케이션의 실행 속도와 다운로드 코드 크기 간에 상충 관계를 만드나요?
-
예. 최적화 컴파일러는 모두 절충을 합니다. 일부 크기 최적화는 약간의 속도 오버헤드를 도입합니다. 하지만 Closure Compiler의 개발자는 상당한 추가 런타임을 도입하지 않도록 주의했습니다. 컴파일러의 일부 최적화는 런타임을 줄이기도 합니다 (다음 질문 참고).
-
컴파일러가 속도에 맞게 최적화하나요?
-
다운로드 시간이 일반적으로 웹 애플리케이션에서 가장 중요한 속도 요소이므로 대부분의 경우 코드가 작을수록 속도가 빠릅니다. 중복을 줄이는 최적화는 코드 실행 시간도 단축합니다.
-
컴파일할 수 있는 파일 크기에 제한이 있나요?
-
컴파일 웹 서비스에는 최대 파일 크기가 있지만 독립형 컴파일러 애플리케이션에는 없습니다.
-
Closure Compiler는 모든 플랫폼에서 사용할 수 있나요?
-
컴파일러는 Java로 작성되어 있으므로 Java가 실행되는 곳이라면 어디에서나 실행할 수 있습니다.
-
컴파일러가 모든 합법적인 JavaScript를 처리할 수 있나요?
-
대부분
eval()
및 with()
을 비롯한 일부 JavaScript 구조는 컴파일러의 변환이 기반으로 하는 가정을 무효화할 수 있습니다.
-
Closure Compiler를 사용하려면 웹 개발에 대해 얼마나 알아야 하나요?
-
Closure Compiler는 JavaScript 개발 도구이므로 컴파일러를 사용하려면 JavaScript로 프로그래밍하는 방법을 알아야 합니다. 하지만 JavaScript를 사용하는 사람이라면 누구나 Closure Compiler를 사용하면 이점을 얻을 수 있습니다.
-
Closure Compiler는 Closure Library와 어떻게 작동하나요?
-
Closure Compiler는 Closure Library를 사용하는 코드에 특별한 검사와 최적화를 제공합니다. 또한 Closure Compiler 서비스는 Closure Library 파일을 자동으로 포함할 수 있습니다. Finding Your Way around Closure에서는 필요한 Closure 부분을 선언하는 구문을 설명합니다. API와 함께 Closure Library를 사용하는 방법에 관한 자세한 내용은 API 참조를 참고하세요. Closure Compiler 애플리케이션과 함께 Closure Library를 사용하려면 먼저 Closure Library를 다운로드해야 합니다. Closure Library 지원은 컴파일러 애플리케이션에서 기본적으로 사용 설정되어 있습니다.
-
ADVANCED_OPTIMIZATIONS
로 컴파일하면 코드가 작동하지 않거나 컴파일러에서 오류가 발생합니다. 왜냐하면
-
고급 모드를 사용하려면 일반적으로 준비 작업과 코드 변경이 필요합니다. 고급 컴파일 및 Externs에서는 코드가
ADVANCED_OPTIMIZATIONS
에서 작동하는지 확인하는 방법을 설명합니다.
-
컴파일된 스크립트에 임의의 줄바꿈이 있는 이유는 무엇인가요?
-
Closure Compiler는 의도적으로 약 500자마다 줄바꿈을 추가합니다. 방화벽과 프록시는 때때로 매우 긴 줄이 있는 대규모 JavaScript 파일을 손상시키거나 무시합니다. 500자마다 줄바꿈을 추가하면 이 문제를 방지할 수 있습니다. 줄바꿈을 삭제해도 스크립트의 시맨틱스에는 영향을 주지 않습니다. 코드 크기에 미치는 영향은 작으며 컴파일러는 파일이 gzip으로 압축될 때 코드 크기 페널티가 훨씬 작아지도록 줄바꿈 배치를 최적화합니다.
-
소스 코드에 표시되어야 하는 저작권 고지 또는 오픈소스 라이선스 텍스트가 있습니다. Closure Compiler가 이 텍스트를 삭제하지 않도록 하려면 어떻게 해야 하나요?
-
Closure Compiler는 JSDoc
@license
태그를 지원합니다. 컴파일러 출력에서 주석을 유지하려면 JSDoc 주석에 @license
태그를 추가하세요. 자세한 내용은 Closure Compiler용 JavaScript 주석 달기를 참고하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eThe Closure Compiler is a tool for making JavaScript download and run faster by reducing file size and improving efficiency.\u003c/p\u003e\n"],["\u003cp\u003eIt offers greater compression than standard minifiers and helps identify syntax errors and potential bugs during development.\u003c/p\u003e\n"],["\u003cp\u003eThe Closure Compiler works with any valid JavaScript and can be used alongside other minifiers for enhanced optimization.\u003c/p\u003e\n"],["\u003cp\u003eSource maps enable debugging of compiled code by providing a mapping back to the original source.\u003c/p\u003e\n"],["\u003cp\u003eWhile prioritizing download speed, the compiler also performs optimizations to enhance execution speed without significant runtime overhead.\u003c/p\u003e\n"]]],[],null,["# Frequently Asked Questions\n\n- [What is the Closure Compiler? Why should I use it?](#what)\n- [How is the Closure Compiler different\n from the other JavaScript compressors that are out there?](#how-different)\n- [Can the Closure Compiler compile JavaScript that's embedded in HTML?](#tags)\n- [Can I use the Closure Compiler together with other JavaScript\n minifiers?](#other-minifiers)\n- [How can I debug the JavaScript that the Closure Compiler produces?](#sourcemaps)\n- [Does the compiler make any trade-off between my application's\n execution speed and download code size?](#tradeoffs)\n- [Does the compiler optimize for speed?](#speed)\n- [Are there any restrictions on the size of the files that can be compiled?](#size-restrictions)\n- [Is the Closure Compiler available for all platforms?](#platforms)\n- [Can the Compiler process any legal JavaScript?](#restrictions)\n- [How does the Closure Compiler work with\n the Closure Library?](#how-closure)\n- [My code stops working or the Compiler produces\n errors when I compile\n with `ADVANCED_OPTIMIZATIONS`. Why?](#advanced)\n- [Why are there random line feeds in\n compiled scripts?](#linefeeds)\n- [I have copyright notices or open source license\n text that must appear in my source code. How do I keep the Closure\n Compiler from stripping this text out?](#license)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\nWhat is the Closure Compiler? Why should I use it?\n:\n The Closure Compiler is a tool for making JavaScript download and\n run faster. You can use the Closure Compiler to reduce the size of\n your JavaScript files and to make them more efficient.\n\n\nHow is the Closure Compiler different from the other JavaScript\ncompressors that are out there?\n\n: Generally, the Closure Compiler should meet or exceed the compression\n of other code minification tools, and improve download times for your\n web application. In addition, the Closure Compiler can help you\n find syntax errors during development (rather than during testing)\n and identify potentially buggy code patterns.\n\n In Simple mode, Closure Compiler should be able to do better than\n other tools because it uses compiler-like analysis to find additional\n ways to minimize code size. For example, the Closure Compiler can\n inline functions that are used in only a few occurrences, reuse\n variable names, and pre-compute constant expressions.\n\n In Advanced mode, Closure Compiler can also use your added type\n annotations to find hard-to-spot bugs.\n\n\nCan the Closure Compiler compile JavaScript that's embedded in HTML?\n:\n No. The Closure Compiler works only on files that contain only JavaScript.\n\n\nCan I use the Closure Compiler together with other JavaScript\nminifiers?\n\n: Yes. Closure Compiler reads in any valid JavaScript and generates\n valid JavaScript, so you can apply the Closure Compiler to a\n JavaScript file either before or after you run the file through a\n different minifier.\n\n Remember that Closure Compiler and other minifiers might have\n expectations about the incoming code. A minifier that strips\n comments may remove licenses or annotation information needed by\n another tool, for example.\n\n\nHow can I debug the JavaScript that the Closure Compiler produces?\n:\n If your compiled code is throwing errors or exhibiting unexpected behavior,\n you can use Source Maps to debug the issue. A source map provides a mapping\n between the compiled code and the original source code so that the browser's\n developer tools can show you your original source code instead of the compiled code.\n To make the Closure Compiler produce a source map, pass the\n `--create_source_map` flag on the command line. For example: \n\n ```\n $ java -jar compiler.jar --js example.js --create_source_map ./example-map --js_output_file example-compiled.js\n ```\n\n Then, if you're using a browser that supports Source Maps (such as Chrome\n or Firefox), you can set breakpoints just as you would for uncompiled code,\n and the browser's developer tools will show the corresponding line of code\n in the original source. For more information about Chrome's developer tools, including\n information about source maps, see\n [Debugging JavaScript](https://developers.google.com/chrome-developer-tools/docs/javascript-debugging).\n\n\nDoes the compiler make any trade-off between my application's\nexecution speed and download code size?\n:\n Yes. Any optimizing compiler makes trade-offs. Some size\n optimizations do introduce small speed overheads. However, the\n Closure Compiler's developers have been careful not to introduce\n significant additional runtime. Some of the compiler's\n optimizations even decrease runtime (see next question).\n\n\nDoes the compiler optimize for speed?\n:\n In most cases smaller code is faster code, since download time is usually the most important speed factor in web applications. Optimizations that\n reduce redundancies speed up the run time of code as well.\n\n\nAre there any restrictions on the size of the files that can be compiled?\n:\n The compilation web service has a maximum file size, but the\n standalone compiler application does not.\n\n\nIs the Closure Compiler avalable for all platforms?\n:\n The compiler is written in Java, so it can run anywhere Java runs.\n\n\nCan the Compiler process any legal JavaScript?\n:\n Mostly. Some JavaScript constructs, including `eval()`\n and `with()`, can invalidate assumptions on which the\n compiler's transformations are based.\n\n\nHow much do I need to know about web development to use the\nClosure Compiler?\n:\n The Closure Compiler is a tool for JavaScript development, so you\n do need to know how to program in JavaScript to use the\n compiler. But anyone who uses JavaScript can benefit from using\n the Closure Compiler.\n\n\nHow does the Closure Compiler work with the Closure Library?\n:\n The Closure Compiler provides special checks and optimizations for\n code that uses the Closure Library. In addition, the Closure\n Compiler service can automatically include Closure Library\n files. [Finding\n Your Way around Closure](/closure/library/docs/introduction#deps) describes the syntax for declaring the\n parts of Closure that you need. See\n the [API\n reference](/closure/compiler/docs/api-ref#closure) for information on using the Closure Library with the\n API. To use the Closure Library with the Closure Compiler\n application you must\n first [download\n the Closure Library](https://github.com/google/closure-library). Support for the Closure Library is\n enabled in the compiler application by default.\n\n\nMy code stops working or the Compiler produces errors when I\ncompile with `ADVANCED_OPTIMIZATIONS`. Why?\n:\n Using Advanced mode usually requires some preparation and code\n changes. [Advanced Compilation\n and Externs](/closure/compiler/docs/api-tutorial3) explains how to make sure your code works\n with `ADVANCED_OPTIMIZATIONS`.\n\n\nWhy are there random line feeds in compiled scripts?\n:\n The Closure Compiler intentionally adds line breaks every 500\n characters or so. Firewalls and proxies sometimes corrupt or\n ignore large JavaScript files with very long lines. Adding line\n breaks every 500 characters prevents this problem. Removing the\n line breaks has no effect on a script's semantics. The impact on code size is small, and the Compiler\n optimizes line break placement so that the code size penalty is even smaller when files are gzipped.\n\n\nI have copyright notices or open source\nlicense text that must appear in my source code. How do I keep the\nClosure Compiler from stripping this text out?\n:\n Closure Compiler supports the JSDoc `@license` tag. Add the\n `@license` tag to any JSDoc comment to preserve the\n comment in the compiler\n output. See [Annotating\n JavaScript for the Closure Compiler](/closure/compiler/docs/js-for-compiler#tag-license) for more information."]]