Closure Compiler ऐप्लिकेशन का इस्तेमाल शुरू करना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Closure Compiler ऐप्लिकेशन का Hello World
Closure Compiler ऐप्लिकेशन, Java की कमांड-लाइन यूटिलिटी है. यह JavaScript को कंप्रेस करती है, ऑप्टिमाइज़ करती है, और उसमें मौजूद गड़बड़ियों का पता लगाती है. आसान JavaScript प्रोग्राम के साथ Closure Compiler ऐप्लिकेशन को आज़माने के लिए, यहां दिया गया तरीका अपनाएं.
इस कसरत को पूरा करने के लिए, आपके पास Java Runtime Environment का वर्शन 7 होना चाहिए.
-
Closure Compiler पैकेज डाउनलोड करना
closure-compiler
नाम की एक वर्किंग डायरेक्ट्री बनाएं.
हाल ही में रिलीज़ हुई JAR फ़ाइल को Maven रिपॉज़िटरी से डाउनलोड करें और उसे closure-compiler
में सेव करें.
-
JavaScript फ़ाइल बनाना
नीचे दिए गए JavaScript कोड के साथ hello.js
नाम की फ़ाइल बनाएं:
// A simple function.
function hello(longName) {
alert('Hello, ' + longName);
}
hello('New User');
इस फ़ाइल को closure-compiler
डायरेक्ट्री में सेव करें.
-
JavaScript फ़ाइल को कंपाइल करना
closure-compiler
डायरेक्ट्री से यह कमांड चलाएं:
java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js
इस कमांड से hello-compiled.js
नाम की एक नई फ़ाइल बनती है. इसमें यह JavaScript होता है:
function hello(a){alert("Hello, "+a)}hello("New User");
ध्यान दें कि कंपाइलर ने टिप्पणियों, वाइटस्पेस, और गैर-ज़रूरी सेमी-कोलन को हटा दिया है. कंपाइलर ने पैरामीटर के नाम longName
को छोटे नाम a
से बदल दिया है. इसका नतीजा यह होता है कि JavaScript फ़ाइल का साइज़ बहुत कम हो जाता है.
यह पुष्टि करने के लिए कि कंपाइल किया गया JavaScript कोड अब भी सही तरीके से काम कर रहा है, hello-compiled.js
को इस तरह की एचटीएमएल फ़ाइल में शामिल करें:
<html>
<head><title>Hello World</title></head>
<body>
<script src="hello-compiled.js"></script>
</body>
</html>
एचटीएमएल फ़ाइल को किसी ब्राउज़र में लोड करें. आपको एक अच्छा मैसेज दिखेगा!
अगले चरण
इस उदाहरण में, Closure Compiler की ओर से किए गए सबसे सामान्य ऑप्टिमाइज़ेशन के बारे में बताया गया है. कंपाइलर की सुविधाओं के बारे में ज़्यादा जानने के लिए, ऐडवांस कंपाइलेशन और Externs पढ़ें.
Closure Compiler के लिए अन्य फ़्लैग और विकल्पों के बारे में ज़्यादा जानने के लिए, --help
फ़्लैग के साथ JAR फ़ाइल को एक्ज़ीक्यूट करें:
java -jar compiler.jar --help
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThe Closure Compiler is a Java command-line tool used to compress, optimize, and debug JavaScript code.\u003c/p\u003e\n"],["\u003cp\u003eThis guide provides a basic example of using the Closure Compiler to minify a simple "Hello World" JavaScript function.\u003c/p\u003e\n"],["\u003cp\u003eThe compiler removes unnecessary elements like comments and whitespace, shortens variable names, and produces a smaller, more efficient JavaScript file.\u003c/p\u003e\n"],["\u003cp\u003eYou can confirm the functionality of the compiled code by including it in an HTML file and loading it in a browser.\u003c/p\u003e\n"]]],[],null,["# Getting Started with the Closure Compiler Application\n\nThe Hello World of the Closure Compiler Application\n---------------------------------------------------\n\n\nThe Closure Compiler application is a Java command-line utility that\ncompresses, optimizes, and looks for mistakes in your JavaScript. To\ntry out the Closure Compiler application with a simple JavaScript\nprogram, follow the steps below.\n\n\nTo work through this exercise you need the Java Runtime Environment\nversion 7.\n\n1. **Download the Closure Compiler package**\n\n\n Create a working directory called `closure-compiler`.\n\n\n Download the most recently released JAR file from the\n [Maven repository](https://mvnrepository.com/artifact/com.google.javascript/closure-compiler), and\n save it in `closure-compiler`.\n2. **Create a JavaScript file**\n\n\n Create a file named `hello.js` containing the following\n JavaScript: \n\n ```carbon\n // A simple function.\n function hello(longName) {\n alert('Hello, ' + longName);\n }\n hello('New User');\n ```\n\n\n Save this file in the `closure-compiler` directory.\n3. **Compile the JavaScript file**\n\n\n Run the following command from\n the `closure-compiler` directory: \n\n ```\n java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js\n ```\n\n\n This command creates a new file\n called `hello-compiled.js`, which contains the following\n JavaScript: \n\n ```text\n function hello(a){alert(\"Hello, \"+a)}hello(\"New User\");\n ```\n\n\n Note that the compiler has stripped comments, whitespace and an\n unnecessary semi-colon. The compiler has also replaced the parameter\n name `longName` with the shorter name `a`. The\n result is a much smaller JavaScript file.\n\n\n To confirm that the compiled JavaScript code still works correctly,\n include `hello-compiled.js` in an HTML file like this\n one: \n\n ```text\n \u003chtml\u003e\n \u003chead\u003e\u003ctitle\u003eHello World\u003c/title\u003e\u003c/head\u003e\n \u003cbody\u003e\n \u003cscript src=\"hello-compiled.js\"\u003e\u003c/script\u003e\n \u003c/body\u003e\n \u003c/html\u003e\n ```\n\n\n Load the HTML file in a browser, and you should see a friendly greeting!\n\n### Next Steps\n\n\nThis example illustrates only the most simple optimizations\nperformed by the Closure Compiler. To learn more about the\ncompiler's capabilities, read [Advanced\nCompilation and Externs](/closure/compiler/docs/api-tutorial3).\n\n\nTo learn more about other flags and options for the Closure\nCompiler, execute the jar with the `--help` flag: \n\n```\njava -jar compiler.jar --help\n```"]]