WPCode Logo

WPCode Blog

Everything you need to know about the WPCode plugin

How To Exclude Specific Scripts From Minification In WP Rocket

How To Exclude Specific Scripts From Minification In WP Rocket 

Do you want to exclude specific scripts from minification in WP Rocket? 

If you’ve ever noticed that certain scripts or styles on your WordPress site aren’t loading as expected, it might be because of how cache plugins optimize files. 

Popular caching plugins, such as WP Rocket, boost your site’s performance by combining multiple JavaScript (JS) or CSS files into a single one. This reduces the number of HTTP requests, which helps your site load faster. 

However, this process can also cause certain scripts or styles—especially custom ones added through WPCode—to load incorrectly.

So, in this article, we’ll show you how to exclude specific scripts from minification in WP Rocket.

Why Exclude Specific Scripts From Minification In WP Rocket?

Minification reduces file sizes by removing unnecessary characters, such as spaces, line breaks, and comments, and combining them into a single file. WP Rocket is one of the most popular caching plugins that provides this feature. 

However, for custom scripts added through plugins like WPCode, this can create issues as they may not load correctly when combined. Here are a few reasons why you’d want to exclude scripts:

  1. Late Loading: Some scripts need to load early to function properly. Combining them with other scripts might delay their execution, breaking your site’s functionality.
  2. Script Conflicts: Some JavaScript libraries or external scripts (e.g., those from third-party APIs) may conflict when combined, causing errors or features to stop working.
  3. Improved Debugging: Excluding certain scripts from minification can help in debugging issues since the original, unminified version is easier to read.
  4. Third-Party JavaScript Libraries: If you’re using third-party libraries like jQuery or Google Maps through WPCode, combining or minifying them can cause errors. For instance, Google Maps often relies on being loaded in a specific sequence, and combining it with other scripts could break map functionality.
  5. Inaccurate Analytics: If you’ve added custom tracking scripts (e.g., Google Analytics, Facebook Pixel) via WPCode, minification could disrupt the script’s ability to communicate with external servers, causing inaccurate tracking data.

How To Exclude Specific Scripts From Minification In WP Rocket

Excluding certain scripts from minification in WP Rocket is fairly simple. For the purpose of this tutorial, let’s assume you have WP Rocket installed and activated. 

Now, please navigate to Settings > WP Rocket. From here, click on the “File Optimization” tab. This section allows you to enable or disable minification for JavaScript and CSS files.

Scroll down to the “JavaScript Files” section. Now, you need to follow either one of the two following methods: 

Method 1: For WPCode Lite Users: Exclude In-line JavaScript

If you’re using WPCode light, all codes are added in line. Therefore, you need to copy a unique string in the inline JavaScript you wish to exclude. Then, you paste the code in the “Excluded Inline JavaScript” field.

How to Exclude Specific Scripts from Minification in WP Rocket: Exclude in-line JavaScript

Method 2: For WPCode Pro Users: Exclude JavaScript Files

If you know the URL path of the script you want to exclude from minification, you need to insert that in the “Excluded JavaScript Files” field. That’s it! 

How to Exclude Specific Scripts from Minification in WP Rocket: Exclude JavaScript Files

If you have more than one file, write them in separate lines. If you need to remove all the files from a specific sub-folder, you can use a wildcard (.*). In case you need to exclude an external JavaScript file hosted on an external domain, you can put the full URL or just the domain in this field. 

After adding the necessary scripts to the exclusion list, scroll down and click “Save Changes.” WP Rocket will now leave these scripts untouched during the minification process.

WPCode Pro users have the ability to load scripts as files. In that case, you can view the file URL path by visiting your site’s admin dashboard > Code Snippets. Then, open the snippets in Edit mode. You’ll find the file URL by clicking the “View File” button in the “Insertion” section. 

How to Exclude Specific Scripts from Minification in WP Rocket: View Script Path in WPCode Pro.

Finally, make sure to check the scripts you excluded are working as expected. You can use the browser’s developer tools (Inspect Element) to check if the scripts are loading properly and debug any potential issues.

Conclusion

Minifying files can boost your website’s performance, but knowing when and how to exclude certain scripts can significantly boost user experience.

We hope you learned how to exclude specific scripts from minification in WP Rocket from this article. We think you’ll benefit from learning how to tell if a page is cached in WordPress as well. 

Get WP Code Pro if you’d like to add advanced features to your website! 

Add A Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.


Get WPCode

Popular Resources

Get free tips and resources right in your inbox, along with 500+ others

Follow Us

Get Started Today & Add Your Own Snippets

Future-proof your website with WPCode Snippets and improve the way you manage code across all your websites.