अक्सर पूछे जाने वाले सवाल
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
-
Closure Compiler क्या है? मुझे इसका इस्तेमाल क्यों करना चाहिए?
-
Closure Compiler एक ऐसा टूल है जिसकी मदद से JavaScript को तेज़ी से डाउनलोड और चलाया जा सकता है. Closure Compiler का इस्तेमाल करके, JavaScript फ़ाइलों का साइज़ कम किया जा सकता है. साथ ही, उन्हें ज़्यादा असरदार बनाया जा सकता है.
-
Closure Compiler, JavaScript को कंप्रेस करने वाले अन्य टूल से किस तरह अलग है?
-
आम तौर पर, Closure Compiler को कोड छोटा करने वाले अन्य टूल की तुलना में, बेहतर तरीके से कोड को कंप्रेस करना चाहिए. साथ ही, आपके वेब ऐप्लिकेशन के डाउनलोड होने में लगने वाले समय को कम करना चाहिए. इसके अलावा, Closure Compiler की मदद से डेवलपमेंट के दौरान (टेस्टिंग के दौरान नहीं) सिंटैक्स से जुड़ी गड़बड़ियों का पता लगाया जा सकता है. साथ ही, गड़बड़ी वाले कोड पैटर्न की पहचान की जा सकती है.
सिंपल मोड में, Closure Compiler को अन्य टूल की तुलना में बेहतर काम करना चाहिए. ऐसा इसलिए, क्योंकि यह कंपाइलर की तरह विश्लेषण करके, कोड के साइज़ को कम करने के अतिरिक्त तरीके ढूंढता है. उदाहरण के लिए, Closure Compiler इनलाइन फ़ंक्शन का इस्तेमाल सिर्फ़ कुछ मामलों में कर सकता है. साथ ही, यह वैरिएबल के नामों का फिर से इस्तेमाल कर सकता है और कॉन्स्टेंट एक्सप्रेशन को पहले से कंप्यूट कर सकता है.
ऐडवांस मोड में, Closure Compiler, जोड़ी गई टाइप एनोटेशन का इस्तेमाल करके, ऐसे बग ढूंढ सकता है जिन्हें ढूंढना मुश्किल होता है.
-
क्या Closure Compiler, एचटीएमएल में एम्बेड किए गए JavaScript को कंपाइल कर सकता है?
-
नहीं. Closure Compiler सिर्फ़ उन फ़ाइलों पर काम करता है जिनमें सिर्फ़ JavaScript होती है.
-
क्या Closure Compiler का इस्तेमाल, अन्य JavaScript minifier के साथ किया जा सकता है?
-
हां. Closure Compiler, किसी भी मान्य JavaScript को पढ़ता है और मान्य JavaScript जनरेट करता है. इसलिए, Closure Compiler को JavaScript फ़ाइल पर लागू किया जा सकता है. ऐसा, फ़ाइल को किसी दूसरे मिनिफ़ायर से चलाने से पहले या बाद में किया जा सकता है.
ध्यान रखें कि Closure Compiler और अन्य minifier, आने वाले कोड के बारे में कुछ उम्मीदें रख सकते हैं. टिप्पणियों को हटाने वाला कोई मिनीफ़ायर, लाइसेंस या एनोटेशन की ऐसी जानकारी हटा सकता है जिसकी ज़रूरत किसी दूसरे टूल को होती है.
-
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 को प्रोसेस कर सकता है?
-
ज़्यादातर. कुछ JavaScript कंस्ट्रक्ट, जैसे कि
eval()
और with()
, उन मान्यताओं को अमान्य कर सकते हैं जिनके आधार पर कंपाइलर के ट्रांसफ़ॉर्मेशन किए जाते हैं.
-
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 के उन हिस्सों को डिक्लेयर करने के सिंटैक्स के बारे में बताया गया है जिनकी आपको ज़रूरत है. एपीआई के साथ Closure Library का इस्तेमाल करने के बारे में जानकारी पाने के लिए, एपीआई रेफ़रंस देखें. Closure Compiler ऐप्लिकेशन के साथ Closure Library का इस्तेमाल करने के लिए, आपको पहले Closure Library डाउनलोड करनी होगी. Closure Library के लिए सहायता, कंपाइलर ऐप्लिकेशन में डिफ़ॉल्ट रूप से चालू होती है.
-
ADVANCED_OPTIMIZATIONS
का इस्तेमाल करके कंपाइल करने पर, मेरा कोड काम नहीं करता या कंपाइलर गड़बड़ियां दिखाता है. क्यों?
-
ऐडवांस मोड का इस्तेमाल करने के लिए, आम तौर पर कुछ तैयारी और कोड में बदलाव करने पड़ते हैं. ऐडवांस कंपाइलेशन और एक्सटर्न में बताया गया है कि यह कैसे पक्का किया जाए कि आपका कोड
ADVANCED_OPTIMIZATIONS
के साथ काम करता है.
-
कंपाइल की गई स्क्रिप्ट में लाइन फ़ीड क्यों दिखते हैं?
-
Closure Compiler, हर 500 वर्णों के बाद जान-बूझकर लाइन ब्रेक जोड़ता है. फ़ायरवॉल और प्रॉक्सी, कभी-कभी बहुत लंबी लाइनों वाली बड़ी JavaScript फ़ाइलों को खराब कर देते हैं या उन्हें अनदेखा कर देते हैं. हर 500 वर्णों के बाद लाइन
ब्रेक जोड़ने से, इस समस्या को रोका जा सकता है. लाइन ब्रेक हटाने से, स्क्रिप्ट के सिमैंटिक पर कोई असर नहीं पड़ता. कोड के साइज़ पर इसका कम असर पड़ता है. साथ ही, कंपाइलर लाइन ब्रेक की जगह को ऑप्टिमाइज़ करता है, ताकि फ़ाइलों को gzip करने पर कोड के साइज़ पर लगने वाला जुर्माना और भी कम हो जाए.
-
मेरे पास कॉपीराइट की सूचनाएं या ओपन सोर्स लाइसेंस का टेक्स्ट है, जिसे मेरे सोर्स कोड में दिखना चाहिए. मैं Closure Compiler को इस टेक्स्ट को हटाने से कैसे रोकूं?
-
Closure Compiler, JSDoc
@license
टैग के साथ काम करता है. कंपाइलर के आउटपुट में टिप्पणी को बनाए रखने के लिए, किसी भी JSDoc टिप्पणी में @license
टैग जोड़ें. ज़्यादा जानकारी के लिए, Closure Compiler के लिए JavaScript को एनोटेट करना लेख पढ़ें.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 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."]]