How to Minify CSS and JavaScript (Fix Guide)
Your audit found CSS or JavaScript files served with their original whitespace, comments, and long variable names intact. Minification strips those non-functional characters so the browser downloads and parses less code, which improves load time and Core Web Vitals. Most fixes are one setting in an optimization plugin, a build-tool flag, or a platform toggle.
What this means
Minification removes everything a browser doesn't need to execute your code: whitespace, line breaks, indentation, comments, and (for JavaScript) long variable names. A main.css file with tidy formatting might be 120 KB; the minified equivalent is often 20-40% smaller with byte-for-byte identical behavior.
The audit flagged unminified_resources because it found one or more .css or .js files where the served content still contains human-readable formatting. The crawler detects this by looking for a high ratio of whitespace, comment blocks (/* ... */), and newlines relative to actual code.
This is distinct from compression (gzip/Brotli). Compression happens at the server transport layer and shrinks the bytes on the wire; minification shrinks the source itself. They stack: a minified file that is also Brotli-compressed is smaller than either technique alone. A warning here means the minification step is missing, even if compression is already on.
Why it matters
Every unminified byte is a byte the browser has to download and then parse. For render-blocking CSS in the <head> and synchronous scripts, that directly delays first paint and pushes out Largest Contentful Paint (LCP), which Google wants under 2.5 seconds. Bloated JavaScript also lengthens parse and compile time on the main thread, which hurts Interaction to Next Paint (INP), the responsiveness metric Google wants under 200ms. PageSpeed Insights surfaces this as the "Minify CSS" and "Minify JavaScript" opportunities with estimated KB savings.
The impact is largest on mobile, where CPUs are slower and connections are worse. Core Web Vitals are a confirmed ranking signal, and beyond ranking they gate real user experience: slow pages get abandoned before they convert.
For AI answer engines, the angle is subtler but real. Crawlers behind ChatGPT, Perplexity, and Google's AI Overviews fetch pages on a time and resource budget. Leaner assets mean faster, more reliable fetches and less chance of a timeout on a heavy page that leaves your content half-rendered and uncited. Minification alone won't get you cited, but it removes a friction point that can keep AI crawlers from fully rendering your content.
How to fix it
- 1
Confirm which files are actually unminified
Open a flagged CSS or JS file directly in the browser (click its URL in View Source). If you see indentation, comments, and full-length variable names, it is unminified. In Chrome DevTools, the Network tab shows transferred vs. resource size, and the Coverage tab shows how much of each file goes unused. Note whether the culprit is your own theme code, a plugin, or a third-party script you don't control, because the fix differs for each.
- 2
WordPress: use one optimization plugin
Do not hand-edit theme files. Install a single optimization plugin and enable its minify options: WP Rocket (File Optimization > Minify CSS files / Minify JavaScript files), Autoptimize (tick Optimize CSS Code and Optimize JavaScript Code), or LiteSpeed Cache (Page Optimization > CSS Settings / JS Settings). Yoast and Rank Math do not minify, so pair them with one of these. After enabling, click through your key pages, because the file-combining features bundled alongside minify occasionally break sliders or forms. If something breaks, exclude that specific script rather than turning minification off.
- 3
Custom and headless sites: minify at build time
If you ship code through a bundler, minification belongs in your build, never patched onto live files. Vite and Next.js minify production builds automatically (
vite build,next build); confirm you are deploying the production build and not running a dev server. For manual setups, esbuild is the fastest option, or use Terser for JS and cssnano for CSS. See the code example for an esbuild one-liner and package.json scripts. - 4
Handle third-party scripts you can't minify
You cannot minify a script hosted on someone else's domain (analytics, chat widgets, ad tags). For those, the fix is loading strategy, not minification: add
asyncordefer, load them after user interaction, or self-host where the license allows. Exclude external URLs from your optimizer so it doesn't try and fail to process them, and minify only the files you actually serve. - 5
Re-test and verify nothing broke
After deploying, clear every cache layer: plugin cache, CDN cache, and browser. Re-run PageSpeed Insights and re-crawl with this tool to confirm the warning clears. Then click through interactive elements one more time: forms, menus, carousels, add-to-cart. Minification is behavior-preserving in theory, but the combine and defer features often bundled with it are the usual cause of post-minify breakage.
Example
# One-off: minify a single file with esbuild
npx esbuild src/main.js --minify --outfile=dist/main.min.js
npx esbuild src/style.css --minify --outfile=dist/style.min.css
# In package.json — run automatically on every build:
# {
# "scripts": {
# "build:js": "esbuild src/main.js --bundle --minify --outfile=dist/main.min.js",
# "build:css": "esbuild src/style.css --minify --outfile=dist/style.min.css",
# "build": "npm run build:js && npm run build:css"
# }
# }
# Dedicated alternatives:
npx terser src/main.js --compress --mangle -o dist/main.min.js # JS
npx cssnano src/style.css dist/style.min.css # CSS
# Then reference the minified files in your HTML:
# <link rel="stylesheet" href="/dist/style.min.css">
# <script src="/dist/main.min.js" defer></script>Minify CSS and JS with esbuild (a single binary that handles both), or with the dedicated Terser and cssnano tools.
Platform-specific steps
Yoast and Rank Math don't minify, so add one dedicated optimization plugin. WP Rocket: File Optimization > enable Minify CSS files and Minify JavaScript files. Autoptimize: Settings > Autoptimize > tick Optimize CSS Code and Optimize JavaScript Code. LiteSpeed Cache: Page Optimization > CSS Settings / JS Settings > enable CSS Minify and JS Minify. Enable, purge cache, then test forms and sliders. Exclude any script that breaks rather than disabling minify.
Shopify automatically minifies theme CSS and JavaScript from the assets folder when referenced via {{ 'file.css' | asset_url }} (CSS since 2021, JS since 2021). It does not minify inline styles/scripts in Liquid templates or third-party app scripts loaded from external servers. If you're flagged, the source is almost always a third-party app injecting raw code, or unminified code you pasted inline. Minify inline snippets before pasting, and audit installed apps for heavy injected scripts.
Both platforms minify their own platform assets automatically, so you can't and don't need to touch those. A warning here points to custom code you added: Wix Custom Code or Velo embeds, or Squarespace Code Injection and code blocks. Minify that snippet yourself before pasting it, or load it with defer so it doesn't block rendering.
Both minify production builds by default. Run next build or vite build and deploy the output; do not ship a dev server to production. Confirm you're serving the build, not running next dev or vite. If you still flag, the culprit is usually a static asset in /public served as-is. Minify those with esbuild before committing them.
Cloudflare deprecated Auto Minify on August 5, 2024 and now recommends minifying at the origin during your build. Don't rely on a CDN toggle. Minify at the source or build step, then let Cloudflare handle Brotli compression and caching on top for the largest combined savings.
Frequently asked
Minification rewrites the source file to remove whitespace, comments, and long names, so the file itself is smaller. Compression (gzip or Brotli) is applied by the server as the file is sent and shrinks the bytes on the wire, then the browser decompresses it. They are complementary, and you should use both. A minified file that is also Brotli-compressed downloads faster than using either technique alone.
Minification by itself is behavior-preserving and safe. Breakage almost always comes from a separate feature bundled with it in optimization plugins: combining files into one bundle, or changing execution order via defer. If something breaks after you enable minify, don't disable the whole feature. Identify the specific script, add it to your plugin's exclusion list, and re-test.
Indirectly. Minification reduces file size, which improves load time and Core Web Vitals like LCP and INP, and Core Web Vitals are a confirmed Google ranking signal. The effect of minification alone is usually small, but it is a low-risk, one-time fix that stacks with other performance work, and faster pages reduce bounce and improve conversions regardless of ranking.
The audit checks the actual file contents, not the filename. A file called bundle.min.css that still contains comments and indentation is not minified, it was just named that way. Open it in your browser and look at the raw content. If it is still human-readable, the minification step never ran, and you need to fix your build or plugin configuration.
Never hand-edit files to strip whitespace on a live site, because you lose the readable source and can introduce errors. Use automation: a build tool (Vite, esbuild, Terser, cssnano) for custom sites so the minified output is generated at deploy time, or an optimization plugin for WordPress. This keeps your development source readable while serving minified files to users.
Does your site have this issue?
Run a free, AI-powered audit and we’ll flag this and 150+ other checks in about a minute. No signup.