Skip to main content

Command line interface

The Google Page Speed Optimizer extension provides several CLI commands to test page speed, optimize images, and manage WebP conversion. These commands are especially useful for bulk operations, maintenance tasks, or integrating into deployment scripts.

Available commands

1. Run a PageSpeed test

bin/magento mirasvit:optimize-insight:pagespeed https://example.com/

What it does: performs a Google PageSpeed Insights analysis for the specified URL and returns performance metrics. Useful for testing whether your optimizations are effective or diagnosing speed issues.


2. Validate image optimization environment

bin/magento mirasvit:optimize-image:validate

What it does: checks if your server environment meets the necessary requirements for image optimization (e.g. presence of required libraries or binaries). Use this after deployment or server changes to confirm image tools will work properly.


3. Run image optimization/WebP conversion

bin/magento mirasvit:optimize-image:optimize [--image] [--webp]

What it does: optimizes your store’s existing images and optionally generates WebP versions of them.

  • --image runs standard image compression/optimization according to your configured quality settings.
  • --webp generates WebP-format versions based on your WebP compression configuration. If you run the command without any flags, it assumes both image optimization and WebP generation (if allowed by configuration). This same process also runs automatically via cron, so this CLI is primarily useful for manual or bulk triggers.

4. Restore original images

bin/magento mirasvit:optimize-image:restore

What it does: reverts all optimized and WebP images back to their original versions, removing the converted/optimized files. Use this if you need to roll back image optimizations for testing or troubleshooting.


5. Extract critical (above-the-fold) CSS

bin/magento mst:optimize:critical-css:extract --url=https://example.com/

What it does: renders the given URL in a headless Chrome/Chromium browser (over the Chrome DevTools Protocol), collects the CSS actually used above the fold, and prints the minified critical CSS to stdout. Useful for build pipelines and bulk updates of Critical CSS Rules.

Common options:

  • --url — target URL to render (required).
  • --viewport — comma-separated WxH viewport(s), merged together. Default: 1366x768. Example: --viewport=1366x768,375x812.
  • --output — write the extracted CSS to a file instead of stdout.
  • --save-to-rule — save the extracted CSS straight into an existing Critical CSS Rule by ID.
  • --wait-for — CSS selector to wait for before collecting coverage.
  • --timeout — navigation timeout in milliseconds. Default: 30000.
Note

The extractor ships pre-built inside the module (no npm install, no browser download). To run this command the host needs Node.js ≥ 18 and a system Chrome/Chromium binary (set CHROME_PATH if it is in a non-standard location). Run extraction from a build machine, not a locked-down production server. Magento Cloud web nodes have no Node/Chrome, so run it elsewhere and store the result in the rule — see Using critical CSS on Magento Cloud. See Critical CSS Rules for the full workflow.