Skip to main content

Fine-tune optimizations

In some cases, you may want to exclude specific pages from JavaScript or CSS optimization. For example, checkout, cart, or custom module pages may rely on certain scripts or styles that should not be delayed, moved, or minified.

Google PageSpeed Optimizer extension allows you to control this behavior using page patterns and URL rules.

Excluding pages from JavaScript bundles​

Go to: Stores > Configuration > Mirasvit Extensions > PageSpeed Optimizer > JavaScript Optimization

Find the option:

Do not use JavaScript bundles on pages

Each line of this field is a pattern, and a pattern is a part of the URL path. It applies to every page whose URL contains it. To cover one single page instead, specify its full action name.

Each pattern should be entered on a new line.

Examples:

checkout
cart
customer/account
catalogsearch/result
checkout_index_index

So checkout covers /checkout/, /checkout/cart/ and the other checkout pages, while checkout_index_index covers that one page only.

On the listed pages the extension loads the original JavaScript files instead of the bundled versions.

note
  • Patterns are case-sensitive: Checkout does not match /checkout/.
  • A full URL is not matched. Specify checkout, not https://example.com/checkout/.
  • Wildcards are not supported: checkout/* matches nothing — plain checkout already covers those pages.
  • A single / is part of every URL, so it disables JavaScript bundles on the whole store.

The field ships with /checkout, which keeps JavaScript bundles disabled on the checkout pages out of the box.


Excluding files from minification​

Still under JavaScript Optimization, you can find another setting:

Do not minify files

This allows you to list JavaScript file name patterns that should be excluded from minification. Each pattern should also be placed on a new line.

Examples:

checkout.js
custom-slider.js
some-module/

This is useful when a specific script causes issues after being minified. The list affects minification only: it does not exclude files from Merge JavaScript files.

When a script breaks after minification​

When Enable JavaScript Optimization and Minify JavaScript are enabled, JavaScript files are minified by Magento's built-in minifier. In rare cases the minifier changes the code of a script so it is no longer valid. A known example is a text string in double quotes that contains an apostrophe, such as "We're sorry": after minification the quotes around it can become single quotes, and the apostrophe then ends the string too early.

Signs of this problem:

  • a feature works with Minify JavaScript disabled but stops working when it is enabled;
  • the browser console shows SyntaxError (for example, Unexpected identifier) in a .min.js file.

To fix it:

  1. Find the file name in the browser console error.
  2. Add the file name (or a part of its path) to Do not minify files, for example Vendor_Module/js/checkout-widget.js. The field is shown when Minify JavaScript is set to Yes.
  3. Save the configuration, flush the Magento cache, and in production mode run bin/magento setup:static-content:deploy.

The listed file is then loaded in its original, non-minified form, while all other files stay minified.

When a script breaks after merging​

Merge JavaScript files has no exceptions. A file or a page cannot be left out of merging: Do not minify files, Do not use JavaScript bundles on pages and Ignore URL list do not affect it.

Merging can break checkout extensions that use RequireJS mixins or ship their own RequireJS bundle. For example, with Amasty One Step Checkout the console shows errors such as getColspanCarrier is not a function, and with Firecheckout a RequireJS mismatch error.

If a feature works with Merge JavaScript files disabled but breaks when it is enabled:

  1. Set Merge JavaScript files to No. Keep Minify JavaScript enabled: it still reduces file sizes.
  2. Save the configuration, flush the Magento cache, and in production mode run bin/magento setup:static-content:deploy.

See JavaScript optimization for details.


Skipping CSS optimization (optional)​

If you have similar issues with CSS files on specific pages, you can also use exclusions under:

Stores > Configuration > Mirasvit Extensions > PageSpeed Optimizer > CSS Optimization

Add file or URL patterns for pages where CSS merging or minification should be skipped.


Tips for creating patterns​

  • Use action names for Magento-specific routes (e.g., checkout, customer/account).
  • Use URL fragments for direct page paths (e.g., /cart/, /checkout/).
  • Keep one pattern per line.
  • Patterns are partial matches, so /checkout/ will match any checkout-related page.

If a page breaks after enabling optimization, start by adding its URL pattern to the Do not use JavaScript bundles list. Then, test again to confirm if the issue is resolved.