Ticket #115 (closed defect: duplicate)

Opened 8 years ago

Last modified 6 years ago

Compress Javascript

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

Change History

Changed 8 years ago by gogo

  • milestone set to Version 1.0

Changed 8 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.

http://xinha.gogo.co.nz/punbb/viewtopic.php?id=114

Direct link : http://www.codeproject.com/csharp/JSCompress.asp

You need to register to download it, just choose a @mailinator.com 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.

Changed 8 years ago by vivek@…

Changed 8 years ago by ianb@…

Dojo has some code for this (open source and possible to integrate into a build process): http://dojotoolkit.org/docs/compressor_system.html -- 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: http://www.crockford.com/javascript/jslint.html

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.

Changed 8 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.

Changed 7 years ago by anonymous

The tool used by Dean Edwards for his IE7 hack: http://dean.edwards.name/packer/

Also available as a .NET or Perl application: http://dean.edwards.name/download/#packer

Changed 7 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; http://xinha.gogo.co.nz/punbb/viewtopic.php?id=589

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

~ Brice

Changed 7 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);
}

Changed 6 years ago by ray

  • status changed from new to closed
  • resolution set to duplicate

see #10

Note: See TracTickets for help on using tickets.