Opened 16 years ago

Closed 14 years ago

#115 closed defect (duplicate)

Compress Javascript

Reported by: wei Owned by: gogo
Priority: normal Milestone: Version 1.0
Component: Xinha Core Version:
Severity: normal Keywords: dojo, crunch, compact

Change History (9)

comment:1 Changed 15 years ago by gogo

  • Milestone set to Version 1.0

comment:2 Changed 15 years ago by anonymous

Would probably be the best one to use, as another option which apperantly works more out of the box I tested this one with success (Without the option of removing linefeeds that is!) It compressed the htmlarea.js file with 45% which is pretty nice improvement.

Direct link :

You need to register to download it, just choose a address and your set to go. There is supposed to be a command line version aswell, though I only tested it with the GUI which is pretty manual, as you need to copy and paste each file to compress them.

comment:4 Changed 15 years ago by ianb@…

Dojo has some code for this (open source and possible to integrate into a build process): -- Dojo looks like it should have a strong future, so if Xinha uses it there will probably be free benefits in the future (e.g., code to put all the Javascript into a single file, packaging, etc).

Generally the code will be much safer to parse and rewrite if you apply any fixes jslint suggests:

jslint is picky about things like explicit statement termination and other possible error conditions (not aesthetic issues like indentation), and would probably be a good idea to try on Xinha regardless. Mozilla's spidermonkey command-line Javascript runner has a "strict" mode as well, which might give good suggestions.

comment:5 Changed 15 years ago by Kim Steinhaug

  • Keywords dojo crunch compact added

The Dojo looks very interesting, a test crunch on the htmlarea went from 171 807 bytes to 91 734, so almost 50% removed without doing anything.

Doesnt seem that Dojo removes any linefeeds, which is probably good since this removes the typical problem of empty ; at the end of the lines and such.

comment:6 Changed 15 years ago by anonymous

The tool used by Dean Edwards for his IE7 hack:

Also available as a .NET or Perl application:

comment:7 Changed 15 years ago by Brice

Maybe we could also make a Minimal Xinha port? Something w/o all the lang addins (or specific per each lang), stripped/minimal graphics, and less plugins? I posted my setup in the forums;

This of course would be intended for distributing Xinha along w/ webapps

~ Brice

comment:8 Changed 14 years ago by mokhet

Here a piece of PHP to minimize js code I am using and gives me good results without scrambling variables names.

function normalise($code) 
  // Remove multiline comment
  $mlcomment = '/\/\*(?!-)[\x00-\xff]*?\*\//';
  $code = preg_replace($mlcomment, '', $code);

  // Remove single line comment
  $slcomment = '/[^:]\/\/.*/';
  $code = preg_replace($slcomment, '',$code);

  // Remove extra spaces
  $extra_space = '/\s+/';
  $code = preg_replace($extra_space, ' ', $code);

  // Remove spaces that can be removed
  $removable_space = '/\s?([\{\};\=\(\)\\\/\+\*-])\s?/';
  $code = preg_replace('/\s?([\{\};\=\(\)\/\+\*-])\s?/', "\\1", $code);

  return str_replace(array("\r\n", "\n", "\r"), '', $code);

comment:9 Changed 14 years ago by ray

  • Resolution set to duplicate
  • Status changed from new to closed

see #10

Note: See TracTickets for help on using tickets.