Advertisements
Home > Uncategorized > Diff compressed Javascript files

Diff compressed Javascript files

I periodically need to find the differences between two javascript files that have been run through something like uglifyjs.  There are a variety of ways to do this, but I haven’t found a solution that really gets me what I am looking for succinctly.

For a while I used git’s diff, but I found this to be cumbersome and not always available.

Then for a while I used wdiff with colordiff.  That would look like this:

wdiff /path/file1.js /path/file2.js | colordiff

The problem with that is that the output is often really long because compressed js doesn’t have many line feeds, and wdiff doesn’t recognize non-word characters as word boundaries, and compressed js often doesn’t have whitespace to deliniate word boundaries, so the strength of wdiff is somewhat thwarted.

What I really wanted was to split the files into their smaller pieces for diffing.  My latest solution is a bash alias, which looks like this in my .bash_alias file:

alias diffjs='function _diffjs(){ diff -w <(uglifyjs "$1" -b) <(uglifyjs "$2" -b); };_diffjs'

Its not perfect, but in many situations it gets me what I want, assuming of course that uglifyjs is available.

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: