Google PageSpeed Optimizer for Magento 2
Google PageSpeed Optimizer speeds up Magento 2 for Core Web Vitals: it bundles and delays JavaScript, applies critical CSS per page type, converts images to WebP and lazy-loads them without delaying the main image.
Built-in PageSpeed Insights monitoring shows how each change affects the desktop and mobile score of your pages. Works with Luma and Hyvä themes.
- Delay GTM and chat scripts until interaction
- Critical CSS per page type
- JS bundling, minification and deferral
- Image compression and WebP conversion
- Lazy loading that keeps the main image first
- Built-in PageSpeed monitoring
Business Value
Google PageSpeed Optimizer is one Magento 2 speed optimization extension for JavaScript, CSS, HTML and images, with PageSpeed Insights monitoring built into the admin. Its settings map to Core Web Vitals: critical CSS, image preload and lazy loading that keeps the main image first work on Largest Contentful Paint (LCP), while delayed third-party scripts and JS bundling cut the main-thread work behind Total Blocking Time and Interaction to Next Paint (INP).
- Opportunity: Google uses Core Web Vitals as one of its ranking signals, and PageSpeed Insights shows how each page of your store scores on them.
- Problem: A default Magento store loads its JavaScript in the page head, third-party tags such as Google Tag Manager and chat widgets compete with the first screen, and images go out as full-size JPEG and PNG files. PageSpeed Insights reports this as render-blocking resources, long Total Blocking Time and "Improve image delivery". Check your store in PageSpeed Insights.
- Solution: The extension handles these causes from one admin section. It bundles only the JavaScript each page type uses, delays third-party scripts until the visitor interacts, applies critical CSS per page type, converts images to WebP and keeps the most important image out of lazy loading. It works with Luma and Hyvä themes, Mage-OS and Magento Cloud.
How does Magento 2 Speed Optimization work?
The extension works on four fronts. It reduces and reorders JavaScript and CSS so the first screen renders sooner, compresses images and serves them as WebP, loads offscreen images and videos only when visitors reach them, and tracks your PageSpeed score so you can see the effect of every change.
Each option is switched on separately, so you can roll changes out one at a time and check the result before the next step.
Performance Optimization of JavaScript and CSS
Advanced JavaScript bundling
On themes built on RequireJS, such as Luma, Magento loads many separate JavaScript files on every page, including code that page never uses.
JavaScript Optimization builds bundles from the files each page type actually requests on your storefront. A product page gets the scripts product pages need, a category page gets its own set, and code shared by most pages goes into a common bundle. As a result, every page loads fewer and smaller JS files.
Checkout is excluded from bundling by default, and you can exclude any other page. A pre-flight check runs before you turn the option on. If you want fewer HTTP requests on top of the bundles, Merge JavaScript files is available in the same section.
Delay JavaScript until user interaction
Google Tag Manager, chat widgets, analytics and review widgets can take a large share of main-thread time, yet none of them has to run before the visitor does anything.
The extension holds the scripts you choose until the first interaction (a tap, click, key press, scroll or mouse move) or until an optional timeout. This lowers Total Blocking Time without removing any functionality.
You decide what to delay with include and exclude patterns, and Dry Run mode only logs what would be delayed, so you can test safely on a live store. Core scripts are never delayed: RequireJS, jQuery, Knockout, Magento UI, Alpine.js and Magewire on Hyvä, as well as payment and reCAPTCHA scripts. See how to delay Google Tag Manager in the user manual.
Defer JavaScript and CSS to the page bottom
Render-blocking resources are one of the most common PageSpeed Insights findings. By default, Magento loads JavaScript in the page head, so the browser downloads and runs it before it shows the content. CSS files in the head have the same effect.
The extension moves JS and CSS to the bottom of the page, so the main content renders first. Magento's own option covers JavaScript only; here CSS moves too, and you keep control with exceptions: a list of scripts to leave in place and a rule that keeps specific CSS in the head.
Read more about fixing render-blocking resources in Magento 2.
Critical CSS per page type
Critical CSS is the small part of your styles needed to draw the first screen. When it is inlined and the rest of the CSS loads later, the page appears sooner and Largest Contentful Paint improves.
The extension keeps critical CSS as rules. Each rule matches pages by full action name, layout handle or URL pattern, so product, category, CMS and checkout pages, as well as pages of third-party modules, get their own CSS for each store view. When a rule matches, the remaining CSS loads without blocking the first render.
You can paste critical CSS into a rule yourself or let the built-in extractor take it from the real page, on demand or on a schedule. The extractor needs Node.js and Chrome on the server, while the storefront itself stays pure PHP. Setup is described in the user manual.
JS, CSS and HTML minification
Minification removes comments, whitespace and formatting from JS, CSS and HTML files, so the browser downloads less data.
The extension turns on Magento's minification for JS, CSS and HTML from one settings page, each type separately. Scripts that break when minified go on an exception list. Merge CSS files is available in the same place.
Preload fonts and connect early
Some resources the first screen needs, such as web fonts, are referenced deep inside CSS files, so the browser discovers them late.
The extension lets you preload fonts, open early connections (preconnect) to the third-party domains your pages use, and preload the home page hero image, optionally for a specific screen width only. The browser starts these downloads right away instead of finding them later.
Defer YouTube videos and Google Fonts
YouTube embeds and Google Fonts come from third-party servers, slow down the first load and are often flagged by PageSpeed Insights.
The extension replaces each YouTube video with its thumbnail and a play button, and the video loads only when the visitor clicks it. Other iframes, such as maps, can be lazy-loaded too. Google Fonts load without blocking rendering and use font-display: swap, so text stays visible while the font downloads.
Image Optimization: Compression, WebP and Lazy Loading
Images are usually the heaviest part of a page. The extension compresses them, serves them as WebP, loads offscreen images only when needed and makes sure the most important image loads first.
Lazy loading that keeps the main image first
Magento 2.4 lazy-loads product images in category listings only. Banners, CMS and Page Builder images, and background images load right away and compete with the content the visitor sees first.
The extension adds the browser's native lazy loading to images across the store, and to background images set by Page Builder or by the CSS classes you list. Offscreen images load when the visitor scrolls close to them.
The first images on the page skip lazy loading and can get fetchpriority="high", so the Largest Contentful Paint image is never delayed. On product pages, the main gallery photo is preloaded automatically. You can exclude any image by file name or type, and SVG files are skipped by default. More details are on the Lazy Load page.
Image compression
The extension compresses JPEG, PNG and GIF images with standard server tools (jpegoptim, optipng and gifsicle) and checks for you that they are installed. Choose the quality level: 100% (lossless, the default), 90%, 80% or 70%.
Optimization runs in the background by cron or from the command line. You choose whether it scans the media folder or the images your pages actually serve, including theme and static files. You can exclude a format, for example GIF, and restore the original images at any time, all of them or one format only.
WebP conversion
According to Google, lossy WebP images are 25–34% smaller than comparable JPEG files, and lossless WebP images are 26% smaller than PNG.
Once you turn WebP on, the extension creates a WebP copy of each image and serves it in a picture tag, with the original as a fallback for browsers without WebP support. Background images, the product gallery and swatches get WebP too, which helps with the "Improve image delivery" finding in PageSpeed Insights.
Responsive images
For the images you choose by file name pattern, the extension generates a set of smaller copies, so a phone gets an image sized for its screen instead of the desktop one. You can generate and clean up these sets from the admin or the command line.
Built-in PageSpeed Insights Monitoring
List the URLs you want to watch, and the extension runs PageSpeed Insights tests for them by cron, for desktop and mobile. Each page gets its own score history chart, so you can see how every change affects the score without checking pages by hand.
The tests run with your own free Google API key. You can also test any page from the command line.
Run Optimization from the Command Line
Frequent tasks can be run from the command line (CLI) instead of waiting for cron:
- Run a PageSpeed Insights test for a page of your store
- Optimize all images or a specific file or folder
- Create WebP copies of images
- Validate the image tools installed on the server
- Restore original images, all of them or one format only
- Clean up records of deleted images
- Extract critical CSS
See the full list of CLI commands in the user manual.
Full Features List of Google PageSpeed Optimizer
JavaScript Optimization:
- Pre-flight check
- JS bundling by page type
- Exclude pages from bundling
- Delay JavaScript until user interaction
- Dry Run mode for delayed scripts
- Merge JavaScript files
- Minify JavaScript
- Move JavaScript to page bottom
- Ignore URL list
- Defer YouTube videos
- Lazy-load iframes
CSS Optimization:
- Critical CSS rules per page type
- Built-in critical CSS extractor
- Defer non-critical CSS
- Merge CSS files
- Minify CSS files
- Move CSS to page bottom
- Add styles to HTML from CSS resources
- Defer Google Fonts
- Additional CSS styles
Image Optimization:
- JPEG, PNG and GIF compression
- Image quality level
- Image scan strategy
- WebP conversion with fallback
- WebP in product gallery and swatches
- Exclude image formats
- Optimization stats: scanned files, WebP files, saved size
Image Lazy Load:
- Native browser lazy loading
- Lazy-load background images
- Preload first N images
- Preload first N background images
- fetchpriority="high" for preloaded images
- Do not use lazy load for images
HTML Optimization:
- Minify HTML
- Preload fonts
- Preconnect to third-party domains
- Preload home page hero image
- Preload product main image
Command Line Interface:
- Run a PageSpeed Insights test for a page
- Validate the image tools on the server
- Run image optimization
- Create WebP copies of images
- Restore original images
- Extract critical CSS
Responsive images:
- Generate a set of responsive images
- Clean up the created responsive images
- Configure the file naming patterns
Google PageSpeed Insights:
- Google PageSpeed Desktop Score
- Google PageSpeed Mobile Score
- Score history per URL
- Run Google PageSpeed Test
- Specify URLs for monitoring in PageSpeed
The most visible improvement is on images. The module processes formats such as JPEG, PNG and GIF, and tracks which files have already been optimised, avoiding unnecessary reprocessing. In our case, it has processed more than 19,000 images, with an aggregate weight reduction of over 50%. PNGs benefit the most, while JPEGs keep a more balanced compression.
On the JavaScript side, bundling helps reduce the initial load by grouping frontend resources. It is not as visible as image optimisation, but it does show up in load and performance metrics.
The whole process runs in the background and, once configured, requires no day-to-day intervention. The module manages file state and applies optimisations progressively when new files appear.
The key is defining the compression level well from the start. From there, the system stays stable without needing external processes or manual adjustments.
Overall, it is a practical solution for reducing asset weight in Magento without adding complexity to the workflow.
Save time by starting your support request online and we'll connect you to an expert.
How can I speed up Magento 2 without coding?
Install the extension and turn its options on one by one in Stores > Configuration > PageSpeed Optimizer. A safe order is image compression, WebP and lazy loading first, then JavaScript and CSS optimization, then critical CSS and delayed third-party scripts.
Add your key pages to the built-in PageSpeed Insights monitoring to see how each step changes the score. Step-by-step instructions are in the user manual.
Does it work with Hyvä themes?
Yes. Image compression, WebP, lazy loading, preload, delayed third-party scripts and PageSpeed monitoring all work on Hyvä. Delay JavaScript never holds Alpine.js, Magewire or other Hyvä scripts.
JavaScript bundling and merging are built for RequireJS themes such as Luma. Hyvä doesn't use RequireJS, so you don't need these options there.
Will bundling or delaying JavaScript break checkout?
Checkout is excluded from JavaScript bundling by default. Delay JavaScript never holds Magento core scripts, payment scripts (PayPal, Stripe, Klarna) or reCAPTCHA, and Defer Google Fonts is skipped on checkout.
Before delaying scripts on a live store, run Dry Run mode: it only logs which scripts would be delayed.
Do I need Node.js to use critical CSS?
No. You can paste critical CSS into a rule yourself. Node.js and Chrome are needed only for the built-in extractor, which takes the CSS from the real page on demand or on a schedule. If your server can't run them (for example, Adobe Commerce Cloud web nodes), extract the CSS elsewhere and paste it into the rule.
How does JavaScript and CSS optimization work?
The extension bundles only the JavaScript each page type uses, minifies and merges JS and CSS, moves render-blocking files to the bottom of the page, and loads non-critical CSS after the critical CSS of the page. Third-party scripts such as Google Tag Manager can wait until the visitor's first interaction. Fewer and smaller requests mean the first screen renders sooner.
Why convert images to WebP?
WebP gives similar quality at a smaller file size: Google reports lossy WebP images 25–34% smaller than JPEG and lossless ones 26% smaller than PNG. Once you turn WebP on, the extension converts images automatically and keeps the original as a fallback for browsers without WebP support.
How does lazy loading improve Magento performance?
Lazy loading makes offscreen images load only when the visitor scrolls close to them, so the first screen downloads less. The extension uses the browser's native lazy loading, covers background images, and keeps the first images (including the main product photo) out of lazy loading so Largest Contentful Paint isn't delayed. See the Lazy Load page for details.
Can I skip optimization for PNG or GIF images?
Yes. Exclude any format (JPEG, PNG or GIF) from optimization and WebP conversion in the settings. If a format was already optimized, you can restore the originals of that format only from the command line.
Does it convert images to AVIF?
No, the extension converts images to WebP, which all current major browsers support, and keeps the original JPEG, PNG or GIF as a fallback.
srcset and sizes attributes always announced the resized copies as 480 and 800 pixels wide, no matter which widths were set under Responsive images → Config. A desktop copy resized to, say, 1920 pixels was announced as 800, so browsers picked the wrong copy. The attributes now use the configured widths. When the desktop width is left blank, 800 is used so the attribute stays valid.resize-480-2x folder next to the existing ones, and offers it to the browser. Cleanup responsive images removes it together with the other copies. Run Generate responsive images again after updating so the new copies exist; until then, pages keep offering the mobile and desktop copies as before.$1 in a value was expanded as a pattern reference. Values are now escaped, and entities you typed yourself, such as & in a URL, are kept as they are instead of being encoded twice.<style> element and inject markup into the page. The </style sequence was removed in one pass, which could rebuild it from the surrounding text. It is now removed until none is left. The same protection is applied to stylesheets inlined by the Add styles to HTML from CSS resources setting.//) stylesheet links over plain HTTP. Certificates are now verified, and protocol-relative links are fetched over HTTPS. Stylesheets served with an invalid or self-signed certificate (common on staging servers) are no longer inlined; the page loads them normally. Links with an explicit http:// address are still fetched as written.avifenc tool on the server, and your web server must send .avif files with the image/avif content type. When WebP is also on, each image is shown as AVIF where an AVIF copy exists and as WebP everywhere else. This applies to page images, <picture> sources, product images, galleries, swatches and Page Builder background images. GIF images are never queued for AVIF. Browsers without AVIF support do not display these images.bin/magento mirasvit:optimize-image:optimize, which has a new --avif option to make only AVIF copies. bin/magento mirasvit:optimize-image:validate now checks for avifenc. The admin shows a warning when AVIF is on but avifenc is missing, and the image statistics show an AVIF Files count. bin/magento mirasvit:optimize-image:reset also removes AVIF copies.mst_optimize_image_file table gets three new nullable columns, avif_path, avif_hash and avif_quality, plus an index on avif_hash. Run bin/magento setup:upgrade after updating.avifenc fails on one image, the error is logged and the image keeps its compressed and WebP copies; an older AVIF copy of it is removed, so the WebP copy is shown instead of an outdated picture. The failed image is tried again when the avifenc build on the server changes, when AVIF quality changes, or after a week. Older avifenc versions (before 1.0, as shipped with Debian 12 and Ubuntu 22.04) are detected and given the options they understand.bin/magento mirasvit:optimize-image:optimize --image, --webp or --avif now queues only images that need that kind of processing. Before, a run limited to one kind could keep picking up images it would not touch, and then stop early. Images already compressed at the current level are no longer compressed again when their compressed copy is up to date and they only need an AVIF or WebP copy.fonts.googleapis.com/css? link was recognized. The css2?family=… link that Google has given out since 2020 was ignored, so the font stylesheet still blocked page rendering, got no preload and no display=swap, and nothing was logged. Both link types are now deferred. A link that asks for another display mode, such as display=block, now gets swap in its place instead of a second display parameter./media/catalog/media/x.jpg. Those images were not shown in their optimized or WebP form, or a different optimized file was shown in their place.<picture> sources getting a second type attribute when replaced with a WebP or AVIF copy. Browsers read the first one, so they could treat the copy as the original format.bin/magento mirasvit:optimize-image:optimize stopping with an error on stores that keep media on remote storage, such as Amazon S3. The command checked and measured the optimized and WebP copies on the local disk instead of in the bucket.bin/magento mirasvit:optimize-image:optimize saving an image with no size when its optimized or WebP copy was missing. Such an image is now removed from the list with the reason printed, and the next scan adds it again./static/...) got a double slash in their address, so they were not found locally. This slowed down page rendering.:. The button could not find itself on the page, so the action never started and no progress or result was shown.mst_optimize/optimize_image/responsive/image and mst_optimize/optimize_html/preload_fonts in core_config_data). Without this step, stores that last saved these settings on Magento 2.1 or earlier would see them come back empty. Settings already stored as JSON are not changed, and a value that cannot be read is left as is and logged as a warning.Blog
We are committed to being open and transparent with our customers. When you purchase our module, you automatically receive one year of free support service and free updates.
Why is this important?
- Seamless Installation and Configuration: We understand that setting up a new module can take time to configure according to your specific needs. That’s why we offer a full year of free support. Our experienced team is here to assist you with installation, configuration, and any questions you might have. We're eager to share our expertise to ensure you get the most out of your purchase.
- Stay Updated with Magento (Adobe Commerce) Releases: Magento releases new versions approximately every three months. These updates can sometimes introduce compatibility challenges. To keep your store running smoothly, we provide a year of free access to the latest versions of our modules, ensuring that you can upgrade Magento and our modules without encountering any obstacles.
- Subscription Included: Renewing your subscription ensures continued access to the latest updates and support from our team. This means you can be confident that any issues you encounter with the extension will be resolved quickly and efficiently. You can cancel your subscription at any time without any additional fees.
These are our primary. A major portion of our new clients come from referrals from our existing clients. Our professional team of developers, marketers and support staff have invested the best knowledge and experience in the field into our work, so you know you can come back to us again and again.
One year free and high quality support. We go to great lengths to provide maximum satisfaction with every module you have purchased in our store. By helping you with installation, configuration, answering your every question, we do all our best to eliminate any possible problems.
30-days money back guarantee. If you are not satisfied with our extension performance for any reason, we provide a full refund.
We constantly add new features to all our modules, and are always interested in hearing your opinion and implementing your suggested features in our future developments.
We provide an expanded user guide for every aspect of our extension, so you can find answers for all your burning questions.
You can customize extension according to your needs and requirements.
The Module is easy to install and upgrade, just follow our step-by-step user guide. Additionally, the extension is ready to use with the Hyvä theme.
No core modifications. The extension has been tested in a Magento Cloud environment and is fully compatible with it.
Andriy Kovalenko