Thursday, August 13, 2015

Build Optimization - Getting list of big images/files shipped during release

Large images in a webpage is the one of the biggest contributor to performance problems in most web pages. Most of such issues are catched during performance testing when you see large images taking long time to load and also increasing the overall size of page.



Small changes can have a big impact

As a build person I always felt the best time to catch such issues is during build time. A designer might make a mistake of committing large images in Source Control but if we have a mechanism to catch it in next CI build will be great. To make it possible I needed a script which I can hookup with my build or may be jenkins job to take care of this task for me. I used the Linux "find" command with ANT .....wallahhh !!! 
I have list of all JPG/PNG/GIF images which have size greater then 100 kb.

 <target name="get-length">
  <echo file="mail.txt" append="false">List of JPG images :-${line.separator}</echo>
  <exec executable="sh" append="true" output="mail.txt">
     <arg value="-c" />
     <arg value="find /deploy/HEAD -path '*/dist/*' -prune -o -iname '*.jpg' -size +100k -exec ls -lh {} \; | awk '{print $5,$9}'" />
  </exec>
  <echo file="mail.txt" append="true">List of PNG images :-${line.separator}</echo>
  <exec executable="sh" append="true" output="mail.txt">
     <arg value="-c" />
     <arg value="find /deploy/HEAD -path '*/dist/*' -prune -o -iname '*.png' -size +100k -exec ls -lh {} \; | awk '{print $5,$9}'" />
  </exec>
  <echo file="mail.txt" append="true">List of GIF images :-${line.separator}</echo>
  <exec executable="sh" append="true" output="mail.txt">
     <arg value="-c" />
     <arg value="find /deploy/HEAD -path '*/dist/*' -prune -o -iname '*.gif' -size +100k -exec ls -lh {} \; | awk '{print $5,$9}'" />
  </exec>
 </target> 

Hope this helps.

5 comments: