Optimize animated GIF size in command-line
Use gifsicle (available for Mac OS X, Windows, DOS, Debian, FreeBSD and NetBSD).
gifsicle -i anim.gif -O3 --colors 256 -o anim-opt.gif
This will optimize and reduce to 256 colors, if the animation uses more colors (the example image does).
You can reduce the size by reducing the number of colors:
512KB, 256 colors
412KB, 128 colors
340KB, 64 colors
240KB, 32 colors
140KB, 16 colors
Based on another Q&A.