How to Compress JavaScript With NetBeans

Written by cristina puno
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Compress JavaScript With NetBeans
Optimising Web pages include minifying JavaScript files. (ANSI image by DBX60 from

When optimising websites, one of the methods used to increase the speed of a web page is to compress files that contain code such as CSS and JavaScript. The process is called "minifying," which means to render a smaller version of the file. When minifying, unwanted extra characters are omitted such as line breaks and comments. This can be done manually, however, for large files this can be done automatically by using IDEs (integrated development environment) such as NetBeans.

Skill level:
Moderately Challenging

Things you need

  • NetBeans

Show MoreHide


  1. 1

    Download the YUI compression files and YUIAnt (see Resources).

  2. 2

    Save the files in the same directory as the web application you are developing.

  3. 3

    Open your web application project in NetBeans that has the JavaScript file that you want compressed.

  4. 4

    Open "build.xml" and add the following code:

    <project name="YUICompression" default="default" basedir=".">

    <description>Builds, tests, and runs the project YUICompression.</description>

    <import file="nbproject/build-impl.xml"/>

    <target name="-pre-dist" >

    <condition property="">

    <istrue value="${}"/>


    <antcall target="-do-compression"/>


    <target name="-do-compression" unless="" >

    <echo level="info" message="Compressing JavaScript...." />

    <path id="yuicompressor.classpath">

    <fileset dir="${build.dir}/web/WEB-INF/lib">

    <include name="YUIAnt.jar"/>

    <include name="yuicompressor-2.4.2.jar"/>



    <taskdef name="yuicompress" classname="" >


    <path refid="yuicompressor.classpath"/>



    <yuicompress linebreak="16000" warn="false" munge="no" preserveallsemicolons="true"

    outputfolder="${basedir}/${build.web.dir}" >

    <fileset dir="${basedir}/web" excludes="" >

    <include name="*/.js" />



    <echo level="info" message="Compression Complete" />



  5. 5

    Build and run the project. The JavaScript file will become automatically compressed.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.