Skip to content

LiteSpeed Cache CSS and JS Minify Without Breaking Your Site

Turn on LiteSpeed Cache CSS and JS minify, combine and deferred loading one setting at a time, so you keep the speed gain. When a menu or checkout breaks, you find the one file responsible and exclude it instead of switching the feature off.

You switched on minify and combine in LiteSpeed Cache for WordPress (LSCWP, the cache plugin for LiteSpeed web servers). Now a dropdown menu, a slider or the checkout has stopped working. Or you want the speed gain without breaking anything in the first place. The fix is the same in both cases. Turn the CSS and JavaScript (JS) options on one at a time in a fixed order, and test after each one. When something breaks, find the single file responsible and add it to the matching exclude list, so the feature stays on for every other file.

What you’ll accomplish

  • Know what each CSS and JS option on the LSCWP Page Optimization screen changes in the HTML your visitors receive.
  • Enable minify, combine and deferred loading in an order that tells you exactly which setting broke a page.
  • Trace a broken menu or checkout to one file with the browser console and LSCWP’s “view before optimization” switch.
  • Exclude that file from the right list and confirm the fix from the command line with curl.

Prerequisites

  • WordPress running LSCWP on a LiteSpeed or OpenLiteSpeed server, and an administrator login.
  • WP-CLI (the WordPress command-line tool) on the server, if you want the command versions of each step. Every step also works in the admin screens.
  • Shell access with curl and grep, from the server or your own machine.
  • A list of three to five pages that matter: the homepage, a blog post, a page built with your page builder, and the cart and checkout if you sell online.
  • Access to purge any CDN (content delivery network, the edge cache in front of your server) you use, such as QUIC.cloud or Cloudflare.
  • No other optimisation plugin minifying or combining the same files. Two plugins rewriting one page is a common source of breakage on its own.

How it works

LSCWP rewrites the HTML of a page before it is cached. Each CSS and JS setting changes that rewrite in a specific way. The labels below match the CSS Settings, JS Settings, Tuning and Tuning - CSS tabs described in the LSCWP Page Optimization documentation.

  • CSS Minify and JS Minify strip whitespace, line breaks and comments from each file. The code itself is unchanged, so minify rarely breaks anything.
  • CSS Combine and JS Combine merge the separate files into one CSS file and one JS file. This is where breakage starts, because order and scope can shift when scripts that lived apart end up in one bundle.
  • JS Combine External and Inline also pulls inline scripts and third-party files into the bundle. The documentation notes that this helps preserve execution order.
  • Load JS Deferred has three modes. Off leaves scripts alone. Deferred runs scripts after the HTML has finished loading. Delayed waits for the visitor to do something, such as move the mouse or press a key.

The generated files are stored in /wp-content/litespeed/css/ and /wp-content/litespeed/js/. Each file is named after a hash of its contents, so a new file name appears every time the source changes.

Diagram of one page's assets before and after LSCWP Combine: five CSS files become one file under /litespeed/css/, six JS files become one file under /litespeed/js/, and a WooCommerce checkout script listed in JS Excludes loads unchanged as its own file

The diagram shows the result you are aiming for. Most files end up in one bundle per type. The checkout script sits in JS Excludes, so LSCWP leaves it as its own file in its original place. One excluded file costs you almost nothing, and the rest of the page keeps the gain.

Combining matters less than it used to. Under HTTP/1.1 a browser opened only a handful of connections per site, so ten small files queued behind each other. HTTP/2 and HTTP/3, the newer versions of the web protocol, send many files at once over a single connection. A LiteSpeed server speaks both. With them, the savings from combining are small, and a bundle has a cost: change one plugin file and every visitor downloads the whole bundle again. Minify and deferred loading still pay off. Treat combine as optional, and switch it off for good if it causes trouble.

Step-by-step

  1. Record a baseline. Open each test page in a private window, so you see what a logged-out visitor sees. Open the browser console (F12, then Console) and note any errors that already exist. Then count the stylesheets and scripts the homepage loads:

    curl -s https://example.com/ | grep -oE '(href|src)="[^"]+\.(css|js)[^"]*"' | wc -l

    Example output:

    31

    Keep this number. If it is under ten, combining has little to save, and you can stop after the minify steps.

  2. Check the current settings from WP-CLI. Run these from the WordPress directory. The option keys come from the plugin itself, and 0 means off.

    for k in optm-css_min optm-css_comb optm-js_min optm-js_comb optm-js_defer; do
      printf '%s: ' "$k"; wp litespeed-option get "$k"
    done

    Example output:

    optm-css_min: 0
    optm-css_comb: 0
    optm-js_min: 1
    optm-js_comb: 0
    optm-js_defer: 0

    For optm-js_defer, 1 is Deferred and 2 is Delayed. If something is already on, keep it on and test the pages before you go further. You need a clean starting point.

  3. Turn on CSS Minify, then purge. In the admin, go to LiteSpeed Cache → Page Optimization → CSS Settings, set CSS Minify to on and save. From the command line:

    wp litespeed-option set optm-css_min true
    wp litespeed-purge all

    Example output:

    optm-css_min:
    1
    Success: Purge all sent to the web server.

    wp litespeed-purge all also clears the generated CSS and JS files, so the next visit builds fresh ones. Reload each test page in the private window. Compare the console with your baseline and look at the layout. If nothing changed, move on.

  4. Turn on JS Minify. Set JS Minify on the JS Settings tab, or run wp litespeed-option set optm-js_min true, then purge and test again. Click through anything interactive: menus, tabs, forms, the cart. A new console error at this stage is rare and usually points at one badly written script. Exclude it as shown in step 8.

  5. Turn on CSS Combine. Set CSS Combine on (optm-css_comb), purge, and test. Watch for missing icon fonts, missing background images, and blocks that suddenly look different on a page-builder page. These come from rules that now load in a different order. Leave Generate UCSS and Load CSS Asynchronously off for now. They are separate features, covered in LSCWP Critical CSS.

  6. Turn on JS Combine. Set JS Combine on (optm-js_comb), purge, and test every interactive element again, including the checkout. Leave JS Combine External and Inline off on the first pass. If a page now throws an error about something being undefined, try turning External and Inline on before you start excluding. It keeps inline scripts in their original order relative to the bundle.

  7. Set Load JS Deferred to Deferred. Choose Deferred first (wp litespeed-option set optm-js_defer 1), purge, and test. Try Delayed (2) only once Deferred is clean. Delayed gives the biggest drop in early script work. Anything that must run before the first click, such as a cookie banner or a checkout field, then needs to go in JS Deferred / Delayed Excludes. The general trade-offs of deferring scripts are covered in defer, async and minify for WordPress JavaScript.

  8. When a page breaks, find the file and exclude it. First, confirm the optimisation is the cause. Add ?LSCWP_CTRL=before_optm to the broken URL. The LSCWP Toolbox documentation lists it as View Site Before Optimization. If the page works there, the problem is one of your new settings. Next, turn off only the setting you enabled last, purge, and reload. The console error now names the original file instead of the bundle. Then add a unique part of that file’s path to the matching list on the Tuning tab, one entry per line:

    wp litespeed-option set optm-js_exc $'woocommerce/assets/js/frontend/checkout.min.js\njquery.min.js'

    Example output:

    optm-js_exc:
    woocommerce/assets/js/frontend/checkout.min.js
    jquery.min.js

    Turn the setting back on, purge, and retest. Use the list that matches the setting that broke the page:

    • JS Excludes (optm-js_exc): files left out of JS minify and combine.
    • JS Deferred / Delayed Excludes (optm-js_defer_exc): files that load normally while the rest are deferred or delayed.
    • Guest Mode JS Excludes (optm-gm_js_exc): files excluded when Guest Mode, LSCWP’s fast default page for first-time visitors, is on.
    • CSS Excludes (optm-css_exc, on Tuning - CSS): stylesheets left out of CSS minify and combine.

    If the error still points at the bundle after you exclude a file, the culprit is a different file. Repeat with the next file the console names.

Validate it works

Check that LiteSpeed is serving the page from cache:

curl -sI https://example.com/ | grep -i '^x-litespeed-cache'

Example output:

x-litespeed-cache: hit

A miss on the first request after a purge is normal; run it again. If the header is missing, either a CDN is answering in front of the server or the page is not being cached. Check the CDN before you suspect LSCWP.

Then list the optimised files the page references:

curl -s https://example.com/ | grep -oE '/wp-content/litespeed/(css|js)/[^"]+' | sort -u

Example output:

/wp-content/litespeed/css/2b7f0c94e1d3a85f6c0e49b1d7a23e58.css?ver=a41c7
/wp-content/litespeed/js/e60a1f3c8b2d4975a0c1f6e3b84d29c7.js?ver=a41c7

With both combine settings on, you should see one CSS and one JS bundle per page variant. If you see none, the page was cached before you enabled the settings, so purge again. Many entries mean minify is on and combine is off, which is fine.

Finally, confirm each excluded file still loads on its own:

curl -s https://example.com/checkout/ | grep -o 'checkout\.min\.js[^"]*'

Example output:

checkout.min.js?ver=9.3.3

Re-run your baseline count from step 1 and open the console on every test page one last time. A clean console on the checkout matters more than any speed score.

Troubleshooting

“Uncaught ReferenceError: jQuery is not defined” after JS Combine or Deferred. An inline script in the page calls jQuery before the bundle that contains jQuery has run. Try JS Combine External and Inline first, so inline code joins the bundle in its original order. If the error remains, add jquery.min.js to JS Excludes and JS Deferred / Delayed Excludes. You can also add the attribute data-no-defer="1" to an inline script you control, which the LSCWP docs list as an alternative.

Layout shifts or a flash of unstyled content after CSS changes. A flash of unstyled content (FOUC) is the moment the page shows raw HTML before its styles apply. CSS Minify and CSS Combine do not cause it on their own. It usually means Load CSS Asynchronously is on without working critical CSS. Turn that option off and see whether the flash stops. If one block still renders wrongly, find its stylesheet in the Network panel and add it to CSS Excludes.

A checkout or payment script breaks. Payment forms often load a script that must run early and in order. Find it in the console error, then add its path to JS Excludes and JS Deferred / Delayed Excludes. Keep the exclusion even if the error later disappears. A checkout that fails for a few visitors costs more than one extra request.

Optimised files do not regenerate after a theme or plugin update. The cached pages still point at the old bundle. In the admin, use Toolbox → Purge → Purge All - CSS/JS, then purge the page cache, or run wp litespeed-purge all, which does both. If /wp-content/litespeed/css/ grows by thousands of files a day, the docs suggest your theme adds a random string to its CSS. Add that stylesheet to CSS Excludes.

A CDN keeps serving old optimised files. A CDN that caches HTML can keep handing out pages that reference bundles you have already purged, and those return 404 errors. Purge the CDN after every LSCWP purge. Then rerun the curl checks above against your site’s address, not the origin server, to see what visitors actually receive.

When this is the wrong approach

  • Another optimisation plugin already minifies or combines files. WP Rocket, Autoptimize and similar tools rewrite the same tags. Never run two. Pick one, and switch the CSS and JS options off in the other.
  • The page loads only a few small files over HTTP/2 or HTTP/3. Combining saves almost nothing there. Keep minify and deferred loading, and leave combine off.
  • Your speed report flags unused code rather than file count. Minify and combine make files smaller and fewer, but they still load code a page never uses. Removing those files page by page is a separate job, done with an asset manager or a few lines of PHP.
  • You need to debug quickly on a live store. Toolbox → Debug Settings offers Disable All Features for 24 Hours, which turns off caching and optimisation while you investigate. Use it to confirm LSCWP is the cause, then return to step 8.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.