Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Closure Compiler là gì?
Closure Compiler là một công cụ giúp JavaScript tải xuống và chạy nhanh hơn. Thay vì biên dịch từ một ngôn ngữ nguồn sang mã máy, nó biên dịch từ JavaScript sang JavaScript tốt hơn. Công cụ này phân tích cú pháp JavaScript, phân tích, xoá mã không dùng và viết lại cũng như giảm thiểu những gì còn lại. Công cụ này cũng kiểm tra cú pháp, các loại và tham chiếu biến, đồng thời cảnh báo về những lỗi thường gặp trong JavaScript.
Làm cách nào để sử dụng Closure Compiler?
Bạn có thể sử dụng Trình biên dịch Closure làm:
Một ứng dụng Java mã nguồn mở mà bạn có thể chạy từ dòng lệnh.
Một thư viện mà bạn có thể phụ thuộc thông qua Bazel.
Một gói NPM
Để bắt đầu sử dụng trình biên dịch, hãy xem phần "Làm cách nào để bắt đầu" bên dưới.
Lợi ích của việc sử dụng Closure Compiler là gì?
Hiệu quả. Trình biên dịch Closure giúp giảm kích thước tệp JavaScript và tăng hiệu quả của tệp, giúp ứng dụng của bạn tải nhanh hơn và giảm nhu cầu về băng thông.
Kiểm tra mã. Trình biên dịch Closure đưa ra cảnh báo về JavaScript không hợp lệ và cảnh báo về các thao tác có thể gây nguy hiểm, giúp bạn tạo ra JavaScript ít lỗi và dễ duy trì hơn.
Tôi nên bắt đầu bằng cách nào?
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eThe Closure Compiler is a tool that optimizes JavaScript for faster download and execution by analyzing, removing dead code, and minimizing the remaining code.\u003c/p\u003e\n"],["\u003cp\u003eIt offers benefits such as improved efficiency by reducing file size and enhanced code checking by providing warnings for potential issues.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize the Closure Compiler through a command-line application, a simple web interface, or by integrating it into their development workflow via the provided resources and documentation.\u003c/p\u003e\n"]]],[],null,["What is the Closure Compiler?\n-----------------------------\n\n\nThe Closure Compiler is a tool for making JavaScript download and run\nfaster. Instead of compiling\nfrom a source language to machine code, it compiles from JavaScript to\nbetter JavaScript. It parses your JavaScript, analyzes it, removes\ndead code and rewrites and minimizes what's left. It also checks\nsyntax, variable references, and types, and warns about common\nJavaScript pitfalls.\n\nHow can I use the Closure Compiler?\n-----------------------------------\n\n\nYou can use the Closure Compiler as:\n- An open source Java application that you can run from the command line.\n- A library you can depend on via Bazel.\n- An NPM package\n- To get started with the compiler, see \"How do I start\" below.\n\nWhat are the benefits of using Closure Compiler?\n------------------------------------------------\n\n - **Efficiency.** The Closure Compiler reduces the size of\n your JavaScript files and makes them more efficient, helping your\n application to load faster and reducing your bandwidth needs.\n\n - **Code checking.** The Closure Compiler provides warnings\n for illegal JavaScript and warnings for potentially dangerous\n operations, helping you to produce JavaScript that is less buggy and\n easier to maintain.\n\n How do I start?\n ---------------\n\n\n - Download the most recently released JAR file from the [Maven repository](https://mvnrepository.com/artifact/com.google.javascript/closure-compiler).\n - Work through the [Application\n Hello World](/closure/compiler/docs/gettingstarted_app).\n - Read about [Advanced\n compilation](/closure/compiler/docs/api-tutorial3).\n - Explore [the project's source code](https://github.com/google/closure-compiler).\n\n \u003cbr /\u003e"]]