Minify JavaScript and Combine JavaScript - How it works?

What do "minify" and "combine" mean? 

Minify

Minification is the process of removing white space and comments from code. This makes the file size smaller, therefore faster to download. Minification alone does not reduce the number of HTTP requests on your site.

Combine

When Combine JS is enabled, all the JS files and inline scripts are combined into 1 single JS file, therefore reducing the number of HTTP requests on your site. Combining is a best practice when your site uses HTTP/1 but not necessarily when using HTTP/2.

NOTE: Combine JavaScript is automatically disabled when Delay JavaScript Execution is active.


How WP Rocket does it

  • WP Rocket searches the HTML of the page and discovers links to .js files and inline scripts in script tags
  • As of WP Rocket 3.7, external JS (i.e. JS hosted on a different domain) is hosted on your domain and processed by both the minify and combine settings (previously external JS was only processed when Combine JS was active). This addresses browser caching warnings from speed testing tools and reduces the number of DNS resolutions needed.
  • The files are processed and the optimized versions are stored in: cache/min/1
  • If you use WordPress multisite, the folder named /1/ will change to reflect the site number.
  • Minified files contain a query string (?ver=) with the last modified timestamp, for cache busting purposes (as of WP Rocket version 3.8.6)
    Original file: https://example.com/wp-content/themes/twentytwenty/assets/js/index.js?ver=1.5
    Minified file:
    https://example.com/wp-content/cache/min/1/wp-content/themes/twentytwenty/assets/js/index.js?ver=1614629419
  • Combined files use a random string in the filename each time it's regenerated, for cache busting purposes: https://example.com/wp-content/cache/min/1/ddaf06baadef88884af9a86038837e20.js
  • If only Minify is enabled, the order of the files on the page does not change, we just replace the existing JS files with their optimized version.
  • If Combine is enabled, the combined file is inserted into the page just before the closing body tag, so it won't be render-blocking.
  • This optimization is only applied on cached or optimized pages.

Some scripts are automatically excluded

These files will not be processed:

  • Filenames containing .min - they are already minified. Note that 3rd party files with .min in the filename will still be hosted locally, but not further minified.
  • We have some automatic exclusions for plugin and theme compatibilities
  • Localized scripts are excluded
  • Excluded inline scripts
  • Excluded external files
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.