Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

How to Compress Images Automatically in a Build or Deployment Pipeline

Build-time compression creates deployable image files; runtime optimizers and hosted services transform images later. Choose based on your output and hosting requirements.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To deploy compressed static image files, add a build step that reads original images and writes optimized copies to a separate output directory, then make sure your site build and deployment package that directory. If you need images transformed only when visitors request them, use a framework runtime optimizer or a hosted image service instead; neither necessarily creates optimized files in the build artifact.

Choose when images should be transformed

“Image optimization” can mean three different things: generating compressed files during a build, transforming images at request time on your own server, or delivering transformed images through a hosted service. Decide based on what you need to deploy and how the site is hosted.

As an Amazon Associate I earn from qualifying purchases.

Approach When transformation happens What deployment receives Main operational concern
Build-time CLI or API During the build step Generated image files in the build artifact Encoder/plugin configuration, output paths, and quality checks
Framework runtime optimizer When images are requested Optimized responses or cached variants, not necessarily build-generated files Runtime support, CPU and memory use, and framework or platform behavior
Hosted transformations In the hosted image-delivery flow Transformed URLs or responses Service configuration, caching, delivery behavior, and terms

Build compressed files into the deployment artifact

For a static site or asset pipeline, keep original images separate from generated output. Add an image-optimization command before the site bundler or deployment-packaging step, and configure the site to use the generated directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
imagemin 'images/*' --out-dir=build/images

The imagemin CLI documents file paths or glob inputs and an output directory. Its documentation also shows selecting a plugin, such as --plugin=pngquant, and configuring plugin options; the API accepts path or glob inputs, a destination directory, and plugins. See the imagemin CLI documentation.

#1 Best Overall
Nero AI Image Upscaler 365 | Enlarge Images & Sharpen Photos | AI Upscaling to 4K | Fix Blurry & Low-Resolution Pictures | Easy Photo Optimization | 1 PC | Windows 11/10
  • ✔️ AI Upscaling up to 8K: Enlarge small, low-resolution, or old photos with crisp details, clean edges, and fewer artifacts — perfect for prints, social media, blogs, and online galleries.
  • ✔️ Fix blurry or noisy photos: AI restores clarity by enhancing textures, sharpening faces, hair, and fine details while reducing noise and JPEG compression errors.
  • ✔️ Ideal for family photos, scans & mobile images: Improve pictures from smartphones, tablets, digital cameras, scanners, and old archives with professional-quality results.
  • ✔️ Fast & easy 1-click enhancement: Batch-process multiple photos at once and improve image quality instantly — no editing experience required.
  • ✔️ Reliable results & broad file support: Works with JPG, PNG, TIFF and more — stable AI processing even on old, compressed or damaged photos.

This is a starting pattern, not a universal quality preset. Choose lossy or lossless processing, format conversion, quality, metadata handling, and resize limits for your assets. Photographs, logos, and screenshots may need different treatment; the documentation does not establish one setting that is best for every image or repository. Preserve originals where possible so you can change settings without recompressing already-lossy outputs.

Wire the step into the build

  1. Choose source and destination directories. For example, read originals from images/ and write generated assets to build/images. Do not use the generated directory as the source for the next run.
  2. Run compression before packaging. Put the command in the build sequence before the site bundler or deployment packaging step that needs the resulting assets.
  3. Point the site at generated files. Check that pages and CSS reference the output path, not the unprocessed originals.
  4. Include the output in deployment. Confirm that the deploy step packages and publishes the generated directory. A successful compression command alone does not ensure those files reach production.
  5. Check the result. Add project-appropriate checks that expected output files exist and representative images render. If CI caches build outputs, ensure a cache cannot leave stale generated files in the artifact.

Use runtime optimization only when hosting supports it

A framework optimizer may transform images as visitors request them rather than during the build. In its Next.js 14 deployment documentation, Next.js states: “Note that images are optimized at runtime, not during the build.” The page was last updated March 13, 2024; consult the Next.js 14 deployment documentation for the version-specific behavior.

For a self-hosted Next.js server, the same documentation recommends considering Sharp for more performant production image optimization and notes that Linux may require additional configuration to avoid excessive memory use. Sharp’s installation guidance says package managers select a matching prebuilt binary for the current operating system and CPU architecture where available. Its documented input formats include JPEG, PNG, Ultra HDR, WebP, AVIF, TIFF, GIF, and SVG. See Sharp installation guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If CI builds on one operating system or architecture and the deployed runtime uses another, follow Sharp’s cross-platform installation guidance rather than assuming the workstation’s binary will work in the deployment image. Runtime optimization also requires an environment that supports the framework’s runtime behavior; it is not a substitute for files that must already exist as compressed static assets.

Account for static export and deployment mode

Next.js 14 supports a custom image loader for Image Optimization with static export. Its documentation distinguishes that from a Node.js deployment using next start, which supports the framework’s features. For static-only hosting, choose a build-time compressor or a compatible external loader; do not expect the built-in server optimizer to materialize every image variant in a static build. See the Next.js 14 deployment documentation and its static export documentation.

Current Next.js self-hosting documentation also describes runtime optimization and notes that separately optimizing images yourself is one reason to disable the built-in optimizer while retaining other next/image benefits. Check the documentation for the Next.js version and hosting mode you actually deploy: the version 14 deployment details above are explicitly version-specific.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use hosted transformations for URL-based delivery

A hosted image service can transform assets in its delivery flow rather than emitting compressed files in your build. Cloudinary documents q_auto for automatic quality selection and f_auto for automatic format selection; its Next.js SDK documentation describes applying these optimizations to transformed image URLs. The documentation says default optimizations affect delivered images while leaving original files unchanged. See Cloudinary image optimization and Cloudinary Next.js image transformations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This model fits a project whose image sources and delivery flow can use hosted transformations and CDN URLs. Before choosing it, verify that URL-based delivery meets your requirements for build artifacts, caching, privacy, and operations. Automatic delivery optimization is not evidence that the build emitted optimized image files.

Best Value
Scrivar PDF Pro - Organize, Edit, Compress, Convert, Merge, eSign, OCR & 30+ tools | Lifetime License
  • EVERY PDF TOOL UNLOCKED - 30+ tools in one app: edit text and images, convert, merge, split, compress, sign, OCR, redact, watermark, batch process, and more. No feature gates, no upsells, nothing held back.
  • PAY ONCE, OWN FOREVER — A one-time purchase, not a subscription. Other apps runs $240/year — Scrivar is yours for life, with free updates included.
  • UNLIMITED eSIGN, BUILT IN — Send contracts and forms for signature and track every step. Recipients sign in their browser with no account or app needed. Replace DocuSign and save hundreds a year.
  • PC, MAC, AND WEB — Install on any Win 10/11 PC or macOS 11+ Mac (Intel or Apple Silicon), or work in your browser at scrivar.com. Same tools, same account, everywhere you work.
  • OCR + FULL OFFICE CONVERSION — Turn scanned documents into searchable, selectable text, and convert PDFs to and from Word, Excel, and PowerPoint with formatting kept intact.

Check pipeline and deployment compatibility

  • Static asset deployment: generate files into a known output directory and verify that the deploy step includes it.
  • Runtime optimization: verify that the deployed framework and host support the optimizer, and account for runtime CPU and memory needs.
  • Native dependencies: for Sharp, match installation to the target OS and CPU architecture, especially when CI and production differ.
  • Static export: use a custom loader or build-time processing where required instead of expecting a server-side optimizer in static output.
  • Quality control: select settings for the image types in the project and review representative results; no universal setting is established for all asset types.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.