23

I need to compare two minimized Javascript files. Most common diff viewers list differences per line, but this isn't useful when the script is compressed to a few lines.

Are there any good tools for comparing minimized Javascript files?

Ram
  • 3,092
  • 10
  • 40
  • 56
Jørgen
  • 8,820
  • 9
  • 47
  • 67
  • 1
    You could use a JS formatter to tidy them up, then compare them. [Closure Compiler](http://closure-compiler.appspot.com/home) can do it if you select "Whitespace only" and "pretty print" – Nathan MacInnes Dec 21 '11 at 12:02
  • Closure Compiler output will not make for a valid comparison because it obfuscates the code. – austincheney Dec 21 '11 at 12:22
  • @austincheney, not if it is only run with whitespace only and pretty-print. Then it only pretty print the file. – Stephen Chung Dec 21 '11 at 15:28
  • This is a messy solution, but I split up my files so that they had one character per line, sorted the lines, and then diffed ignoring whitespace. It's far from perfect but it is enough for what I'm doing. – xdhmoore Feb 15 '17 at 19:12

3 Answers3

12

Pretty Diff tool will diff two minified files or a minified to a beautified file with a single button click.

http://prettydiff.com/

It operates by first minifing files to remove comments and the beautifies the source code before running its diff algorithm. This is my tool, so if this does not do what you need I do take requests.

austincheney
  • 1,097
  • 7
  • 8
  • I seem to get an error loading the page: error on line 74 at column 90: EntityRef: expecting ';' I'm accessing it through Glype, though... I'll check back later. – Jørgen Dec 21 '11 at 12:07
  • Try refreshing. I ran the code through JSLint, which indicated no syntax problems. The application is entirely JavaScript so it does not make HTTP requests for processing. I am guessing you have an incomplete download. – austincheney Dec 21 '11 at 12:17
  • Now I get a "Connection refused". – Jørgen Dec 21 '11 at 12:20
  • The web hosting company had an outage. The first time you must have caught as it was on the blink. Its back up now. – austincheney Dec 21 '11 at 13:19
  • It is summer 2021 and this is still an excellent tool to compare minified js, thank you! – Ivana Jul 22 '21 at 15:38
1

Compressed java script files may not be compared directly. First format both the java script codes using java script beautifier. Then you can compare using any of the below tools:

Tools to compare the code:

  1. Beyond Compare
  2. Compare plugin available in Noteapad++
  3. WinMerge
  4. Prettydiff
  5. Kompare

Tools to Format the Javascript: 1. JavaScriptBeautifier.com

All above tools are available on internet and can be searched and downloaded on google.

Umesh Patil
  • 10,475
  • 16
  • 52
  • 80
1

Our SmartDifferencer tool compares the code using the language syntax rather than text lines. By doing this, it isn't sensitive to or bollixed by formatting or minification.

It doesn't print "lines" containing differences; rather it prints out the code fragment which is different, whether that fragment covers several lines or is only a fragment in a current line. So it would probably do a good job of this.

There is a SmartDifferencer specific to each language, and in particular there is one for JavaScript.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341