Setup & site building · Guide
How to Compress WordPress Website (Step by Step)

Short answer
Compress a WordPress site in layers. Use an image plugin to shrink and resize images, convert them to WebP or AVIF, and make sure Gzip or Brotli is enabled on your server or CDN. Then minify CSS and JavaScript in a caching plugin and clean up the database, testing the site after each change.
Key takeaways
- Images are usually the largest part of a page, so compress and resize them first.
- WordPress supports WebP uploads from 5.8 and AVIF from 6.5.
- Many hosts and CDNs already apply Gzip or Brotli; check the content-encoding header.
- Minify CSS and JavaScript one at a time and test after each change.
- Back up before database cleanup, since deleted data is gone for good.
How do you compress a WordPress website?
Compress a WordPress site in four layers: shrink images, turn on Gzip or Brotli for text files, minify CSS and JavaScript, and clean out database bloat.
Images usually give the biggest saving, because they make up most of the weight on a typical page. Text compression is next, and it is often a single setting.
You do not need every tool on the market. One image plugin, one caching or performance plugin, and a quick check on your server's compression settings cover most sites.
Why does compressing your site matter?
Smaller pages download faster, which improves load times on mobile connections, helps Core Web Vitals scores, and reduces bandwidth on your hosting plan.
Page weight adds up quickly. A single uncompressed photo straight from a phone camera can be several megabytes, which is more than the rest of the page combined.
Speed also affects how visitors behave. Slow pages lose people before they read anything, so compression is one of the cheapest ways to keep them.
Before you start, run your homepage and a key post through PageSpeed Insights. Note the total page size and any warnings about images or text compression so you can compare later.
| Layer | What it shrinks | Typical tool |
|---|---|---|
| Image compression | Photos and graphics | An image optimisation plugin |
| Text compression | HTML, CSS, JavaScript | Gzip or Brotli on the server or CDN |
| Minification | CSS and JavaScript files | Caching or performance plugin |
| Database cleanup | Revisions, transients, spam | Optimisation plugin or WP-CLI |
Step 1: How do you compress images in WordPress?
Install an image optimisation plugin, let it compress new uploads automatically, then run its bulk tool on your existing media library.
Popular options include Smush, ShortPixel, EWWW Image Optimizer, Imagify and Optimole. Most offer a free tier with limits, so compare what each includes before choosing.
Pick a compression level that suits your images:
- Lossless keeps every pixel but saves less space.
- Lossy removes detail most people cannot see and saves far more.
- Glossy or similar middle settings aim for a balance on photos.
For most blogs and business sites, lossy or a middle setting is the right default. Our comparison of Smush and ShortPixel compression results shows how these choices affect file size.
Always keep backups of the originals, either through the plugin's backup option or your normal site backups. That way you can re-compress later if you change settings.
If you want to see what a plugin does before installing it, the Smush plugin page on WordPress.org lists its free features, limits and settings. Most other image plugins publish similar details on their own pages.
A good image plugin also strips metadata such as camera details and location data. That shrinks files a little and avoids sharing information you never meant to publish.
Step 2: Should you resize images before uploading?
Yes. Resizing images to the largest size your theme actually displays saves more space than compression alone, because a huge image shrunk by the browser is still downloaded in full.
WordPress already helps here. Since version 5.3, it scales down very large uploads, using a default threshold of 2560 pixels, and keeps the original separately.
You can go further. If your content area is 1200 pixels wide, there is little reason to upload a 4000 pixel photo.
Our guide on properly sizing images in WordPress explains how to find the right dimensions for your theme.
Step 3: Should you convert images to WebP or AVIF?
Converting to WebP or AVIF usually cuts file size further than compressing JPEG or PNG, and WordPress core supports uploading both formats on servers that can process them.
WordPress added WebP upload support in version 5.8 and AVIF in version 6.5. Many image plugins can also create WebP or AVIF copies and serve them automatically to browsers that support them.
Check that your server's image library supports the format before relying on it. The Site Health screen under Tools shows details about your server's image handling.
Our guide on serving images in next-gen formats covers conversion plugins, CDN options and fallbacks.
Step 4: How do you turn on Gzip or Brotli compression?
Check whether your server already compresses text files, and if it does not, enable Gzip or Brotli through your host, your caching plugin, your CDN or a server config rule.
Most quality hosts and CDNs enable compression by default. Cloudflare, for example, compresses text responses for visitors automatically.
To check your own site, open your browser's developer tools, go to the Network tab, reload the page and click the main document. Look for a content-encoding response header with gzip or br.
MDN's page on the Content-Encoding header explains what those values mean.
If compression is missing, our guide to enabling Gzip or Brotli compression in WordPress has the exact rules for Apache, Nginx and popular plugins.
Step 5: How do you minify CSS and JavaScript?
Turn on CSS and JavaScript minification in your caching or performance plugin, then test the site carefully, because minifying removes spaces and comments but can occasionally break scripts.
Plugins such as WP Rocket, LiteSpeed Cache, W3 Total Cache and Autoptimize all include minify options.
Minification usually saves less than image work, but it adds up on sites with large theme and plugin files. Combining files is less useful on modern HTTP/2 and HTTP/3 servers, so many sites leave combine off.
Test after each change:
- Turn on CSS minify, clear the cache and check key pages.
- Turn on JavaScript minify, clear the cache and check menus, forms and sliders.
- If something breaks, exclude the file that causes it rather than turning everything off.
Lighthouse's guide to enabling text compression explains how compression and minification work together on text files.
Step 6: Can you remove unused CSS and code?
Yes. Removing CSS and scripts that a page never uses shrinks what each visitor downloads, and several performance plugins can generate trimmed CSS per page automatically.
This step goes beyond compression. Instead of making files smaller, it stops sending files that are not needed.
Common wins include disabling plugin assets on pages that do not use them, such as a contact form script on every post, and dropping unused font weights.
Our guide on removing unused CSS in WordPress covers the plugin settings and the risks to watch for.
Step 7: How do you compress the WordPress database?
Clean out old revisions, spam and trashed comments, expired transients and leftover plugin tables, then optimise the tables, which reduces database size and can speed up queries.
A plugin such as WP-Optimize or Advanced Database Cleaner handles this from the dashboard. You can also limit future revisions by adding a line to wp-config.php.
Back up the database first. Cleanup tools delete data permanently, and a backup makes mistakes easy to undo.
For a full walkthrough, read our guide on optimising the WordPress database.
What about videos and other large files?
Host videos on YouTube, Vimeo or a dedicated video service instead of the media library, and compress PDFs before uploading, because large media files often outweigh everything else.
Self-hosted video eats bandwidth and storage fast. Embeds also offload streaming quality and device support to a service built for it.
Large embeds can still slow pages, so use lazy loading or a click-to-load preview for video players.
WordPress lazy loads images and iframes by default, which means media further down the page only loads when a visitor scrolls near it. That does not make files smaller, but it reduces what loads up front.
Our guide on lazy loading images in WordPress explains when to exclude above-the-fold images so your main hero image still appears quickly.
How do you check that compression worked?
Run the same pages through PageSpeed Insights or a similar tool again, compare the total page weight and warnings with your earlier results, and click through the site to confirm nothing broke.
Look for:
- A smaller total page size.
- No warning about enabling text compression.
- Fewer or smaller image warnings.
- Forms, menus and checkout still working.
Remember to clear your page cache and CDN before testing. Otherwise you may be measuring the old, uncompressed version.
Test on mobile as well as desktop. Mobile scores are usually lower, and they show the benefit of compression most clearly because phones often use slower connections.
Keep a short note of what you changed and when. If a problem appears a week later, that record makes it easy to find which setting caused it.
If scores improve but the site still feels slow, the bottleneck may be hosting or uncached PHP. Our full guide on optimising WordPress speed covers caching, hosting and other fixes beyond compression.
Frequently asked questions
What is the best plugin to compress a WordPress website?
There is no single best plugin. Most sites pair an image plugin such as ShortPixel, Smush or EWWW Image Optimizer with a caching plugin that handles minification. Pick tools that match your host, since some hosts include their own caching and compression features.
Does compressing images reduce quality?
Lossless compression keeps every pixel, so quality stays the same. Lossy compression removes some detail, but at sensible settings most people cannot see the difference on screen. Keep original backups so you can re-process images if you ever want higher quality.
How do I know if Gzip is enabled on my WordPress site?
Open your browser's developer tools, go to the Network tab and reload the page. Select the main document and look at the response headers. A content-encoding value of gzip or br means text compression is working.
Can compression break my WordPress site?
Image compression and Gzip rarely cause problems. Minifying and combining JavaScript is the setting most likely to break menus, sliders or forms. Turn options on one at a time, clear the cache, and test key pages so you can quickly undo the change that caused trouble.
Should I compress my site if I use a CDN?
Yes. A CDN usually handles text compression and may optimise images, but it cannot fix oversized uploads, bloated databases or unused scripts. Compressing at the source keeps the files the CDN stores and delivers as small as possible.
Sources
- PageSpeed Insights Google
- Enable text compression Chrome for Developers
- Content-Encoding MDN Web Docs
- Smush Image Optimization WordPress.org Plugins
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


