Optimize Angular Images — Before the CLI Copies Them
Compress the images in your Angular project's public/ or src/assets folder before ng build. It pairs with NgOptimizedImage and needs nothing added to angular.json.
Quick answer
The Angular CLI copies static images into the build output exactly as they are. NgOptimizedImage adds lazy loading, priority hints and dev-mode warnings, but it does not re-encode your files. Compress the originals with TinyPixels before ng build.
How to compress images before an Angular build
Download and open TinyPixels
Free to install on Mac or Windows — no account needed to start.
Check sizes against rendered boxes
NgOptimizedImage warns in dev mode about oversized images. Resize the ones it flags.
Compress the folder
Drop it into TinyPixels. Convert large banners to WebP and point ngSrc at the new file if you like.
Commit and run ng build
Angular copies the smaller files straight into dist.
What the Angular build does, and does not do, with images
Angular's build tooling is thorough about JavaScript: tree shaking, bundle budgets, optimized output. Static assets get a much lighter touch. Images in the assets list in angular.json (or, in newer projects, the public/ folder) are copied into dist unchanged.
The NgOptimizedImage directive (ngSrc) improves the delivery side. Images lazy-load by default, the priority attribute marks the Largest Contentful Paint image, and the dev server warns when width and height are missing or an image is much larger than its rendered box. That is about how images load, not how many bytes they are.
Bundle budgets in angular.json are mainly configured for JavaScript and stylesheet sizes in the default setup, so a 4 MB hero image in your assets won't trip them. Image weight needs its own check, and the cheapest one is compressing before you commit.
Fits NgOptimizedImage
Use the directive for loading behaviour and TinyPixels for the file size.
assets and public/
Both layouts are covered: compress the folder your project actually uses.
Pre-commit, not per-build
No extra builder, no angular.json changes, nothing to maintain across CLI upgrades.
Format conversion
Convert big banners to WebP and reference the new file in ngSrc.
How Angular handles an image
| Reference | What happens | Your move |
|---|---|---|
| File in public/ or src/assets | Listed as an asset and copied to dist unchanged. | Compress before commit |
| <img ngSrc="..."> (NgOptimizedImage) | Lazy loading, priority hint and dev warnings. Needs width and height, or fill. No re-encoding. | Compress the file ngSrc points to |
| priority attribute | Marks the LCP image so it loads early. | Use on one image per page and compress it |
| url() inside component styles | Resolved during the build. | Compress the referenced file |
| Bundle budgets in angular.json | Cover JavaScript and styles in the default config. | Track image weight separately |
Folder names and defaults differ between Angular CLI versions, so check which layout your project uses.
Common mistakes with Angular project images
Using a plain src with no width or height
Without dimensions the browser can't reserve space and the layout shifts. NgOptimizedImage enforces this; compress the file as well.
Marking every image priority
Priority is for the one image that is the LCP element. Applied everywhere it undoes lazy loading and competes for bandwidth.
Compressing inside dist/
The output folder is regenerated by every ng build, so changes there vanish. Compress the sources you commit.
Assuming budgets will catch heavy images
A passing build only means your JavaScript and styles are in budget. Check image weight yourself.
Frequently asked questions
Does NgOptimizedImage compress images?
No. It improves loading behaviour with lazy loading, priority hints and dev-mode warnings, but it serves your original bytes. Compress the files first.
Where should images go in an Angular project, assets or public?
Newer projects use the public/ folder; older ones list src/assets in angular.json. Both are copied unchanged, so compress whichever your project uses.
Do Angular budgets include images?
In the default configuration, budgets target JavaScript and stylesheet sizes, so they won't warn about a heavy image. Check image weight separately.
Can I use WebP in an Angular app?
Yes. Angular doesn't restrict image formats; reference the .webp file in ngSrc. Browser support is broad today, but keep a fallback if you need to support very old browsers.
Can I batch compress my whole Angular project at once?
Yes. Drop public/ or src/assets into TinyPixels and every image compresses in one local pass.
Trim your Angular build output
Free to start. No credit card, no account, no cloud. See Pro pricing →
Related tools
Optimize Vue Images
Compress images for your Vue app before build.
Optimize React Images
Compress images for your React app before build.
WebP Converter
Convert any format to WebP locally.
Batch Image Compressor
Compress your entire assets folder in one pass.
Image Compressor Hub
Every format, platform, and framework in one place.
Optimize Next.js Images
Compress public assets before deploying Next.js.
Optimize Svelte Images
Compress images for your Svelte app before build.
Optimize Astro Images
Compress images for your Astro site before build.
Read more: Fix your Lighthouse score where it actually matters → · How to reduce image file size without losing quality →