Javascript file compactor wanted

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron Gray

    #1

    Javascript file compactor wanted

    Hi,

    Is there any tool that will concatinate JavaScript files compacting them
    spacewise and removing comment fields ?

    I have some sed script that sort of does the job but was wondering if there
    were any hopefully open source tools that will do the job.

    I don't want encryption or obverscation though.

    Many thanks in advance,

    Aaron


  • Peter Michaux

    #2
    Re: Javascript file compactor wanted


    Aaron Gray wrote:
    Hi,
    >
    Is there any tool that will concatinate JavaScript files compacting them
    spacewise and removing comment fields ?
    >
    I have some sed script that sort of does the job but was wondering if there
    were any hopefully open source tools that will do the job.
    >
    I don't want encryption or obverscation though.
    >
    <URL: http://www.crockford.c om/javascript/jsmin.html>

    Comment

    • pcx99

      #3
      Re: Javascript file compactor wanted

      Aaron Gray wrote:
      Hi,
      >
      Is there any tool that will concatinate JavaScript files compacting them
      spacewise and removing comment fields ?
      >
      I have some sed script that sort of does the job but was wondering if there
      were any hopefully open source tools that will do the job.
      >
      I don't want encryption or obverscation though.
      >
      Many thanks in advance,
      >
      Aaron
      >
      >

      If you have access to your .htaccess file on your web server then you
      can use some rewrite rules to send external javascript files as
      compressed gzip files. The browser will send a header if it can accept
      gzip compression (most every browser can), if it can just pass it the
      script.js.gz file and if it can't have the rewrite engine pass the
      script.js file.

      You'll not get better throughput any other way (and you can leave your
      js files mostly readable since you don't have to strip whitespace).



      --
      http://www.hunlock.com -- Musings in Javascript, CSS.
      $FA

      Comment

      • Peter Michaux

        #4
        Re: Javascript file compactor wanted

        pcx99 wrote:
        Aaron Gray wrote:
        >
        Is there any tool that will concatinate JavaScript files compacting them
        spacewise and removing comment fields ?

        I have some sed script that sort of does the job but was wondering if there
        were any hopefully open source tools that will do the job.

        I don't want encryption or obverscation though.

        Many thanks in advance,

        Aaron
        >
        >
        If you have access to your .htaccess file on your web server then you
        can use some rewrite rules to send external javascript files as
        compressed gzip files. The browser will send a header if it can accept
        gzip compression (most every browser can), if it can just pass it the
        script.js.gz file and if it can't have the rewrite engine pass the
        script.js file.
        >
        You'll not get better throughput any other way (and you can leave your
        js files mostly readable since you don't have to strip whitespace).
        To get the best results use both minimization and compression together.
        The reason both are useful is there is no need to compress and send the
        comments or whitespace.

        <URL: http://yuiblog.com/blog/2006/10/16/pageweight-yui0114/>

        It also helps to reduce the number of JavaScript files by concatenating
        them together

        <URL: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/>

        Peter

        Comment

        • pcx99

          #5
          Re: Javascript file compactor wanted

          Peter Michaux wrote:
          pcx99 wrote:
          >Aaron Gray wrote:
          >>
          >>Is there any tool that will concatinate JavaScript files compacting them
          >>spacewise and removing comment fields ?
          >>>
          >>I have some sed script that sort of does the job but was wondering if there
          >>were any hopefully open source tools that will do the job.
          >>>
          >>I don't want encryption or obverscation though.
          >>>
          >>Many thanks in advance,
          >>>
          >>Aaron
          >>
          >If you have access to your .htaccess file on your web server then you
          >can use some rewrite rules to send external javascript files as
          >compressed gzip files. The browser will send a header if it can accept
          >gzip compression (most every browser can), if it can just pass it the
          >script.js.gz file and if it can't have the rewrite engine pass the
          >script.js file.
          >>
          >You'll not get better throughput any other way (and you can leave your
          >js files mostly readable since you don't have to strip whitespace).
          >
          To get the best results use both minimization and compression together.
          The reason both are useful is there is no need to compress and send the
          comments or whitespace.
          >
          <URL: http://yuiblog.com/blog/2006/10/16/pageweight-yui0114/>
          >
          It also helps to reduce the number of JavaScript files by concatenating
          them together
          >
          <URL: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/>
          >
          Peter
          >
          I just fooled around with the rewrite engine and took my 10k common JS
          file and created a gz version (didn't even tweak the settings) and it's
          now a 3k file. The rewrite engine puts a performance hit on the server
          but that is MORE than overcome by the bandwidth (and to a far lesser
          extent) storage space savings. It won't work for php files but for any
          static html or ANY static file be it .js, .css, etc it will work
          invisibly and transparently. Just drop a gz copy of the file alongside
          the original and if the browser can handle it the server will send the
          compressed file...

          RewriteEngine on
          RewriteOptions Inherit

          #Check to see if browser can accept gzip files.
          ReWriteCond %{HTTP:accept-encoding} (gzip.*)

          #make sure there's no trailing .gz on the url
          #ReWriteCond %{REQUEST_FILEN AME} !^.+\.gz$

          #check to see if a .gz version of the file exists.
          RewriteCond %{REQUEST_FILEN AME}.gz -f

          #All conditions met so add .gz to URL filename (invisibly)
          RewriteRule ^(.+) $1.gz [L]


          --
          http://www.hunlock.com -- Musings in Javascript, CSS.
          $FA

          Comment

          • Rik

            #6
            Re: Javascript file compactor wanted

            pcx99 wrote:
            I just fooled around with the rewrite engine and took my 10k common JS
            file and created a gz version (didn't even tweak the settings) and
            it's
            now a 3k file. The rewrite engine puts a performance hit on the
            server
            but that is MORE than overcome by the bandwidth (and to a far lesser
            extent) storage space savings. It won't work for php files but for
            any static html or ANY static file be it .js, .css, etc it will work
            invisibly and transparently.
            The output of a php file can also easily be gzipped, by using either
            ob_gzhandler() or zlib.output_com pression. Zipping the source is somewhat
            useless as it doesn't get send anyway.
            --
            Rik Wasmus


            Comment

            • Aaron Gray

              #7
              Re: Javascript file compactor wanted

              Thanks Guys I will check these options out.

              Many thanks,

              Aaron


              Comment

              Working...