Getting Started

Excluding the Prices Script from JavaScript Optimisers

Published

Super Speedy AJAX Prices works by loading a small script that fetches each visitor’s real prices after the cached page has rendered. If a performance plugin holds that script back until the visitor interacts with the page, the prices do not update on load, they only refresh when the visitor scrolls or clicks (and sometimes not at all). The fix is one exclusion: keep the plugin’s script out of any “delay JavaScript until interaction” feature.

Which script to exclude

The front-end script is:

/wp-content/plugins/super-speedy-ajax-prices/assets/js/wc-ajax-pricing.js

Optimisers let you match a script by filename, by path, or by handle, so any of these will target it:

  • Filename: wc-ajax-pricing.js
  • Path fragment: /super-speedy-ajax-prices/
  • Script handle: wc-ajax-pricing

The script depends on jQuery. If you exclude our script and prices still do not fire, exclude jQuery from the same delay feature too (jquery.min.js / jquery-migrate), because a delayed dependency delays the script that depends on it.

Delay is the problem, plain defer is fine

These two sound similar but behave very differently, so it is worth being precise:

  • “Load JavaScript deferred” (the defer attribute) is safe. Our script runs on DOMContentLoaded and is enqueued in the footer, so deferring it does not stop prices loading. You can leave this on.
  • “Delay JavaScript execution”, “delay until interaction”, “load scripts on interaction” or “lazy load JavaScript” is what breaks it. These hold every script until the visitor scrolls, moves the mouse or taps, so the price fetch waits for that interaction instead of firing on load.

If your optimiser lumps defer and delay together, or you are not sure which one it is doing, exclude our script from all of its JavaScript optimisation. That costs nothing: the script is tiny and only does anything on pages that have price placeholders.

Common mistake

Leaving wc-ajax-pricing.js under “delay until interaction”. Prices then update only once the visitor scrolls or clicks. Add the script (and jQuery if needed) to the delay exclusions and they fetch on load.

Worked example: Perfmatters

  1. Go to Perfmatters → Assets → JavaScript.
  2. Turn to Delay JavaScript. In the Exclude from Delay box, add wc-ajax-pricing.js (or /super-speedy-ajax-prices/ to be safe). If you use the “Delay All Scripts” mode rather than a specific list, this exclusion box is essential.
  3. If prices still wait for interaction, also add jquery to the same exclude box.
  4. Save and clear any cache, then reload a cached product or category page without touching it.

If you also use the Perfmatters Script Manager to switch scripts off per page, make sure wc-ajax-pricing is left enabled on your shop, product and category pages, otherwise the price fetch never loads at all.

General guidance for any optimiser

Every optimiser has its own name for the interaction-delay feature, but the fix is always the same: find that feature and add our script to its exclusion or allow list.

  • WP Rocket – “Delay JavaScript Execution”. See the dedicated guide below for the exact Rocket steps.
  • Perfmatters – “Delay JavaScript” (worked example above).
  • FlyingPress – “Lazy Load JavaScript”.
  • LiteSpeed Cache – “Load JS Deferred” set to Delayed, and “Guest Mode” JS handling.
  • W3 Total Cache / Autoptimize / SG Optimizer / NitroPack – a “delay JS”, “defer/exclude” or “load on interaction” list.

Add wc-ajax-pricing.js (or /super-speedy-ajax-prices/) to that list. Separately, if a Combine JavaScript feature stops prices updating, add the same exclusion there too, or turn combine off (on HTTP/2 it rarely helps anyway).

How to tell it is working

Load a cached product or category page and do not interact with it. Within a moment of the page appearing, the price should settle from its cached value to the visitor’s real price (dimmed then crisp, in the default mode), not only after you scroll or click. In your browser’s DevTools Network tab you should see the prices request (admin-ajax.php with action=get_wc_prices, or /wp-json/ssap/ for a REST type) fire on load rather than on first interaction.

Further reading

the exact WP Rocket steps for this exclusion, plus its caching and RUCSS settings.
the universal cache rules the prices request needs.
what a visitor sees during the fetch (dimmed, spinner or loading text).
what to check if prices still do not update.

Comments

▲
▼
1/1