Compress JavaScript?

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

    Compress JavaScript?

    Hi,

    the question how to compress JavaScript has been discussed many times
    in the news groups but I didn't find a suitable solution.

    I need a tool, which
    a) does not cost anything
    b) removes all white spaces, comments line breaks and so on
    c) renames functions and variables to the shortest possible names.
    d) converts files statically before making it public (instead of
    compressing it in run-time on the server and perhaps inflating it on
    the client)

    I had a look at jsmin which covers a + b but not c.

    Any other tool? I am about to write one myself but would like to safe
    me the effort if there was something out there...

    Thanks in advance,
    Kay
  • Marek Mänd

    #2
    Re: Compress JavaScript?

    Sparhawk wrote:[color=blue]
    > the question how to compress JavaScript has been discussed many times
    > in the news groups but I didn't find a suitable solution.
    > I need a tool, which
    > a) does not cost anything
    > b) removes all white spaces, comments line breaks and so on
    > c) renames functions and variables to the shortest possible names.
    > d) converts files statically before making it public (instead of
    > compressing it in run-time on the server and perhaps inflating it on
    > the client)
    > I had a look at jsmin which covers a + b but not c.
    > Any other tool? I am about to write one myself but would like to safe
    > me the effort if there was something out there...[/color]

    The time required to write such a tool would have been enormeous.

    I dont know workings of mr Douglas Crockford's jsmin, havent read this
    NG quite some years, but more than 3 years ago the best one on the
    js-scene was mr Thomas Loo's "ESC"



    which outweighed mr Mike Hall's works "JavaScript Crunchinator"

    which was probably the best one available prior ESC came out.

    hope I saved you a lot of time

    --
    marekmand
    Talliinn, Estonia

    Comment

    • Jim Ley

      #3
      Re: Compress JavaScript?

      On 24 Oct 2004 13:41:17 -0700, Kay.Eckernkamp@ gmx.de (Sparhawk) wrote:
      [color=blue]
      >Any other tool? I am about to write one myself but would like to safe
      >me the effort if there was something out there...[/color]

      Just use gzip, it'll beat anything you can do many times over, and is
      infinitely simpler and removes the need of doing QA again after
      crunching.

      Jim.

      Comment

      • Ian Stirling

        #4
        Re: Compress JavaScript?

        Jim Ley <jim@jibbering. com> wrote:[color=blue]
        > On 24 Oct 2004 13:41:17 -0700, Kay.Eckernkamp@ gmx.de (Sparhawk) wrote:
        >[color=green]
        >>Any other tool? I am about to write one myself but would like to safe
        >>me the effort if there was something out there...[/color]
        >
        > Just use gzip, it'll beat anything you can do many times over, and is
        > infinitely simpler and removes the need of doing QA again after
        > crunching.[/color]

        gzip can't quite cut it in all cases.
        For example, some browsers don't do gzip.

        Comment

        • Ian Stirling

          #5
          Re: Compress JavaScript?

          Marek M?nd <cador.soft@mai l.ee> wrote:[color=blue]
          > Sparhawk wrote:[color=green]
          >> the question how to compress JavaScript has been discussed many times
          >> in the news groups but I didn't find a suitable solution.
          >> I need a tool, which
          >> a) does not cost anything
          >> b) removes all white spaces, comments line breaks and so on
          >> c) renames functions and variables to the shortest possible names.
          >> d) converts files statically before making it public (instead of
          >> compressing it in run-time on the server and perhaps inflating it on
          >> the client)
          >> I had a look at jsmin which covers a + b but not c.
          >> Any other tool? I am about to write one myself but would like to safe
          >> me the effort if there was something out there...[/color]
          >
          > The time required to write such a tool would have been enormeous.
          >[/color]
          Not really.
          An hour or two.

          B is trivial.
          I wrote one in about 3 minutes.
          C is a bit harder, and would require a minimal parser, and list of
          reserved words.
          D (compress reserved words by replacing with calls to them using shorter
          names) is a bit harder yet.

          [color=blue]
          > I dont know workings of mr Douglas Crockford's jsmin, havent read this
          > NG quite some years, but more than 3 years ago the best one on the
          > js-scene was mr Thomas Loo's "ESC"
          >
          > http://www.saltstorm.net/depo/esc/crunching.wbm
          >
          > which outweighed mr Mike Hall's works "JavaScript Crunchinator"
          > http://www.brainjar.com/js/crunch/
          > which was probably the best one available prior ESC came out.
          >
          > hope I saved you a lot of time
          >[/color]

          Comment

          • Jim Ley

            #6
            Re: Compress JavaScript?

            On 25 Oct 2004 12:29:49 GMT, Ian Stirling <root@mauve.dem on.co.uk>
            wrote:
            [color=blue]
            >Jim Ley <jim@jibbering. com> wrote:[color=green]
            >> On 24 Oct 2004 13:41:17 -0700, Kay.Eckernkamp@ gmx.de (Sparhawk) wrote:
            >>[color=darkred]
            >>>Any other tool? I am about to write one myself but would like to safe
            >>>me the effort if there was something out there...[/color]
            >>
            >> Just use gzip, it'll beat anything you can do many times over, and is
            >> infinitely simpler and removes the need of doing QA again after
            >> crunching.[/color]
            >
            >gzip can't quite cut it in all cases.
            >For example, some browsers don't do gzip.[/color]

            Can you name some browsers that can do sensible amounts of javascript
            but can't do gzip?

            There may be an issue with proxy caches, but then if the proxy cache
            is there it's going to be saving the bandwidth anyway, that's what
            it's there for, and even this are rare.

            With the additional cost of debugging, QA, I really don't think it
            makes any sense to do this - that is of course unless you have no
            QA...

            Jim.

            Comment

            • Sparhawk

              #7
              Re: Compress JavaScript?

              Thanks,

              the ESC thing is exactly what I have been looking for!

              It's still a shame that I found a tool, I always wanted to program a
              parser myself and started yesterday :))

              Anyway, thanks,
              Sparhawk



              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • Sparhawk

                #8
                Re: Compress JavaScript?

                Jim,

                is the gzip solution standars compliant? I found some examples using the
                archive-property of the script-tag, but read that this was not part of
                the standard.

                Is it supported by all webservers? How's the syntax you would use?

                Thanks,
                Sparhawk



                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                • Jim Ley

                  #9
                  Re: Compress JavaScript?

                  On 25 Oct 2004 15:57:49 GMT, Sparhawk <nospam@devdex. com> wrote:
                  [color=blue]
                  >Jim,
                  >
                  >is the gzip solution standars compliant?[/color]

                  Yes, absolutely, on most servers you also don't need to do anything
                  but turn it on.
                  [color=blue]
                  >Is it supported by all webservers?[/color]

                  You turn on mod_gzip on apache, or tick the "gzip" box on IIS, it's
                  all very simple - you do not change the client in any way at all.

                  First find out what web-server you have and then we can direct you to
                  the documentation.

                  Jim.

                  Comment

                  • Sparhawk

                    #10
                    Re: Compress JavaScript?

                    Jim,

                    my site (http://www.yucata.de) for which I am looking for a solution is
                    hosted by a hosting provider. Thus I have no access to the configuration
                    of the server. But I am sure that it is IIS.

                    How is the correct syntax for requesting a gzip-Javascript in HTML? I
                    will just try if it is turned on.

                    Regards,
                    Kay

                    *** Sent via Developersdex http://www.developersdex.com ***
                    Don't just participate in USENET...get rewarded for it!

                    Comment

                    • Jim Ley

                      #11
                      Re: Compress JavaScript?

                      On 26 Oct 2004 07:27:49 GMT, Sparhawk <nospam@devdex. com> wrote:
                      [color=blue]
                      >How is the correct syntax for requesting a gzip-Javascript in HTML? I
                      >will just try if it is turned on.[/color]

                      It's exactly the same syntax as a non-gzipped one, that's the point of
                      the solution, it's transparent.

                      Are you sure it's not already enabled, if it's IIS6.1 there's a good
                      chance it is.

                      Jim.

                      Comment

                      • Ian Stirling

                        #12
                        Re: Compress JavaScript?

                        Jim Ley <jim@jibbering. com> wrote:[color=blue]
                        > On 25 Oct 2004 12:29:49 GMT, Ian Stirling <root@mauve.dem on.co.uk>
                        > wrote:
                        >[color=green]
                        >>Jim Ley <jim@jibbering. com> wrote:[color=darkred]
                        >>> On 24 Oct 2004 13:41:17 -0700, Kay.Eckernkamp@ gmx.de (Sparhawk) wrote:
                        >>>
                        >>>>Any other tool? I am about to write one myself but would like to safe
                        >>>>me the effort if there was something out there...
                        >>>
                        >>> Just use gzip, it'll beat anything you can do many times over, and is
                        >>> infinitely simpler and removes the need of doing QA again after
                        >>> crunching.[/color]
                        >>
                        >>gzip can't quite cut it in all cases.
                        >>For example, some browsers don't do gzip.[/color]
                        >
                        > Can you name some browsers that can do sensible amounts of javascript
                        > but can't do gzip?[/color]

                        The one on my mobile.
                        It does javascript, not gzip.

                        Comment

                        • Steve Neill

                          #13
                          Re: Compress JavaScript?

                          Checkout ESC from saltstorm.net. I found 2 bugs in it, but can send
                          you patches if you choose to use it. We use it all the time and
                          compresses script to about 50%.

                          Steve

                          Comment

                          • Jim Ley

                            #14
                            Re: Compress JavaScript?

                            On 26 Oct 2004 18:47:35 GMT, Ian Stirling <root@mauve.dem on.co.uk>
                            wrote:
                            [color=blue]
                            >Jim Ley <jim@jibbering. com> wrote:[color=green]
                            >> Can you name some browsers that can do sensible amounts of javascript
                            >> but can't do gzip?[/color]
                            >
                            >The one on my mobile.
                            >It does javascript, not gzip.[/color]

                            Which UA? (which mobile if it's the default one on the pone)

                            Jim.

                            Comment

                            • Marek Mänd

                              #15
                              Re: Compress JavaScript?

                              Steve Neill wrote:
                              [color=blue]
                              > Checkout ESC from saltstorm.net. I found 2 bugs in it, but can send
                              > you patches if you choose to use it. We use it all the time and
                              > compresses script to about 50%.[/color]

                              If its buggy, then why dont you contact the author of it, so he will be
                              notified about the bugs? Would be a proper thing to do...

                              Or has he lost all the interest in it? Dont know.

                              Comment

                              Working...