سوالات متداول
با مجموعهها، منظم بمانید ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
- کامپایلر بسته شدن چیست؟ چرا باید از آن استفاده کنم؟
- Closure Compiler ابزاری برای دانلود و اجرای سریعتر جاوا اسکریپت است. شما می توانید از Closure Compiler برای کاهش حجم فایل های جاوا اسکریپت و کارآمدتر کردن آنها استفاده کنید.
- Closure Compiler چه تفاوتی با دیگر کمپرسورهای جاوا اسکریپت دارد؟
به طور کلی، Closure Compiler باید فشرده سازی سایر ابزارهای کوچک سازی کد را داشته باشد یا از آن فراتر رود و زمان دانلود را برای برنامه وب شما بهبود بخشد. علاوه بر این، Closure Compiler می تواند به شما کمک کند تا خطاهای نحوی را در طول توسعه (به جای آزمایش) پیدا کنید و الگوهای کد باگ بالقوه را شناسایی کنید.
در حالت ساده، Closure Compiler باید بتواند بهتر از سایر ابزارها عمل کند، زیرا از تجزیه و تحلیل کامپایلر مانند برای یافتن راههای اضافی برای به حداقل رساندن اندازه کد استفاده میکند. برای مثال، Closure Compiler میتواند توابعی را که فقط در چند مورد استفاده میشوند درون خطی قرار دهد، نام متغیرها را مجدداً استفاده کند و عبارات ثابت را از قبل محاسبه کند.
در حالت پیشرفته، Closure Compiler همچنین میتواند از حاشیهنویسیهای نوع اضافه شده شما برای یافتن باگهای سخت استفاده کند.
- آیا Closure Compiler می تواند جاوا اسکریپتی را که در HTML جاسازی شده است کامپایل کند؟
- خیر. Closure Compiler فقط روی فایل هایی کار می کند که فقط حاوی جاوا اسکریپت هستند.
- آیا می توانم از Closure Compiler همراه با سایر کوچک کننده های جاوا اسکریپت استفاده کنم؟
بله. کامپایلر بستن در هر جاوا اسکریپت معتبری می خواند و جاوا اسکریپت معتبر تولید می کند، بنابراین می توانید کامپایلر بسته را قبل یا بعد از اجرای فایل از طریق یک مینی فایایر دیگر روی یک فایل جاوا اسکریپت اعمال کنید.
به یاد داشته باشید که Closure Compiler و سایر minifierها ممکن است انتظاراتی در مورد کد ورودی داشته باشند. برای مثال، کوچککنندهای که نظرات را حذف میکند، ممکن است مجوزها یا اطلاعات حاشیهنویسی مورد نیاز ابزار دیگری را حذف کند.
- چگونه می توانم جاوا اسکریپتی را که Closure Compiler تولید می کند اشکال زدایی کنم؟
- اگر کد کامپایل شده شما خطاهایی ایجاد می کند یا رفتار غیرمنتظره ای از خود نشان می دهد، می توانید از Source Maps برای رفع اشکال استفاده کنید. نقشه منبع یک نقشه بین کد کامپایل شده و کد منبع اصلی فراهم می کند تا ابزار توسعه دهنده مرورگر بتواند کد منبع اصلی شما را به جای کد کامپایل شده به شما نشان دهد. برای اینکه Closure Compiler یک نقشه منبع تولید کند، پرچم
--create_source_map
را در خط فرمان ارسال کنید. به عنوان مثال:$ java -jar compiler.jar --js example.js --create_source_map ./example-map --js_output_file example-compiled.js
سپس، اگر از مرورگری استفاده میکنید که از نقشههای منبع (مانند کروم یا فایرفاکس) پشتیبانی میکند، میتوانید نقطههای شکست را دقیقاً مانند کدهای کامپایل نشده تنظیم کنید، و ابزارهای توسعهدهنده مرورگر خط کد مربوطه را در منبع اصلی نشان میدهند. برای اطلاعات بیشتر درباره ابزارهای برنامهنویس Chrome، از جمله اطلاعات مربوط به نقشههای منبع، به اشکالزدایی جاوا اسکریپت مراجعه کنید. - آیا کامپایلر بین سرعت اجرای برنامه من و اندازه کد بارگیری تطبیقی ایجاد می کند؟
- بله. هر کامپایلری که بهینهسازی میشود، معاوضه ایجاد میکند. برخی از بهینهسازیهای اندازه، سربار سرعت کمی را معرفی میکنند. با این حال، توسعه دهندگان Closure Compiler مراقب بوده اند تا زمان اجرا اضافی قابل توجهی را معرفی نکنند. برخی از بهینه سازی های کامپایلر حتی زمان اجرا را کاهش می دهند (به سوال بعدی مراجعه کنید).
- آیا کامپایلر برای سرعت بهینه سازی می کند؟
- در بیشتر موارد کد کوچکتر کد سریعتر است، زیرا زمان دانلود معمولاً مهمترین عامل سرعت در برنامه های وب است. بهینهسازیهایی که افزونگیها را کاهش میدهند، زمان اجرای کد را نیز افزایش میدهند.
- آیا محدودیتی در اندازه فایل های قابل کامپایل وجود دارد؟
- وب سرویس کامپایل حداکثر اندازه فایل را دارد، اما برنامه کامپایلر مستقل اینطور نیست.
- آیا کامپایلر بسته شدن برای همه پلتفرم ها در دسترس است؟
- کامپایلر به زبان جاوا نوشته شده است، بنابراین می تواند در هر جایی که جاوا اجرا شود اجرا شود.
- آیا کامپایلر می تواند هر جاوا اسکریپت قانونی را پردازش کند؟
- بیشتر. برخی از ساختارهای جاوا اسکریپت، از جمله
eval()
و with()
میتوانند مفروضاتی را که تبدیلهای کامپایلر بر اساس آنها انجام شدهاند، باطل کنند. - برای استفاده از Closure Compiler چقدر باید درباره توسعه وب بدانم؟
- Closure Compiler ابزاری برای توسعه جاوا اسکریپت است، بنابراین برای استفاده از کامپایلر باید بدانید که چگونه در جاوا اسکریپت برنامه نویسی کنید. اما هر کسی که از جاوا اسکریپت استفاده می کند می تواند از استفاده از Closure Compiler بهره مند شود.
- چگونه کامپایلر بسته با کتابخانه بسته کار می کند؟
- کامپایلر بسته شدن، بررسی ها و بهینه سازی های ویژه ای را برای کدهایی که از کتابخانه بسته استفاده می کنند، فراهم می کند. علاوه بر این، سرویس Closure Compiler می تواند به طور خودکار فایل های Closure Library را شامل شود. Finding Your Way around Closure نحوی را برای اعلام قسمت هایی از Closure که به آن نیاز دارید توضیح می دهد. برای اطلاعات در مورد استفاده از کتابخانه بسته شدن با API به مرجع API مراجعه کنید. برای استفاده از کتابخانه بسته با برنامه کامپایلر بسته، ابتدا باید کتابخانه بسته را دانلود کنید . پشتیبانی از کتابخانه بسته به طور پیش فرض در برنامه کامپایلر فعال است.
- کد من کار نمی کند یا کامپایلر هنگام کامپایل با
ADVANCED_OPTIMIZATIONS
خطاهایی ایجاد می کند. چرا؟ - استفاده از حالت Advanced معمولاً به مقداری آماده سازی و تغییرات کد نیاز دارد. Advanced Compilation and Externs توضیح می دهد که چگونه مطمئن شوید کد شما با
ADVANCED_OPTIMIZATIONS
کار می کند. - چرا فیدهای خط تصادفی در اسکریپت های کامپایل شده وجود دارد؟
- کامپایلر Closure به طور عمدی هر 500 کاراکتر یا بیشتر شکسته های خط اضافه می کند. فایروال ها و پراکسی ها گاهی اوقات فایل های جاوا اسکریپت بزرگ با خطوط بسیار طولانی را خراب یا نادیده می گیرند. افزودن خط شکستن هر 500 کاراکتر از این مشکل جلوگیری می کند. حذف خطوط شکسته تاثیری بر معنای اسکریپت ندارد. تأثیر روی اندازه کد کم است و کامپایلر جای شکست خط را بهینه می کند تا جریمه اندازه کد در هنگام gzip شدن فایل ها کمتر شود.
- من اعلامیه های حق چاپ یا متن مجوز منبع باز دارم که باید در کد منبع من ظاهر شود. چگونه می توانم از کامپایلر بسته شدن این متن جلوگیری کنم؟
- Closure Compiler از تگ JSDoc
@license
پشتیبانی می کند. برای حفظ نظر در خروجی کامپایلر، تگ @license
را به هر نظر JSDoc اضافه کنید. برای اطلاعات بیشتر به Annotating JavaScript for Close Compiler مراجعه کنید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-24 بهوقت ساعت هماهنگ جهانی."],[[["\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,["- [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."]]