Back to feed
Dev.to
Dev.to
7/20/2026
Auto-Optimize Images in a Git Pre-Commit Hook (Local, No Upload)

Auto-Optimize Images in a Git Pre-Commit Hook (Local, No Upload)

Short summary

A practical tutorial for setting up a local, offline image optimization pre-commit hook using pngquant and jpegoptim. The hook automatically compresses staged PNG and JPEG files before they enter a commit, re-stages the smaller versions, and strips EXIF metadata including GPS coordinates. Also covers team-wide enforcement via the pre-commit framework and compares local vs. SaaS compression approaches. Ends with a brief pitch for the author's browser-based QuickShrink tool.

  • Pre-commit hook with pngquant/jpegoptim compresses staged images locally before commit, no uploads needed
  • Re-staging ensures the optimized version is what gets committed; EXIF stripping removes GPS data
  • pre-commit framework config enables team-wide enforcement and CI checks

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more