Skip to main content

Exclude Files from JavaScript Minification

Updated this week

FlyingPress minifies JavaScript files by default to improve load time and reduce file size. If a script breaks after minification, you can exclude it using the flying_press_exclude_from_minify:js filter.

Where to add this code

Add the snippet to one of the following:

  • Your theme’s functions.php file

  • A custom plugin

  • A plugin like Code Snippets

Example: Exclude JS files from minification

add_filter('flying_press_exclude_from_minify:js', function ($exclude_keywords) {
return [
'slider.js',
'custom/scripts/',
'my-theme',
'/themes/',
'/plugins/sample-plugin/'
];
});

How it works

The filter checks if any part of a JS file’s URL contains one of the keywords. Matching is partial and case-sensitive.

You can use:

  • File name: 'slider.js' matches /assets/js/slider.js

  • Folder path: 'custom/scripts' matches /custom/scripts/app.js

  • Theme-wide exclusion: '/themes/' excludes all scripts from any theme

  • Plugin-wide exclusion: '/plugins/' excludes all plugin JS files

  • Specific plugin: '/plugins/sample-plugin/' excludes only that plugin’s JS

Notes

  • Files excluded from minification can still be deferred or delayed unless excluded separately

  • Only exclude scripts if necessary—minification improves performance in most cases

  • For CSS exclusions, use the flying_press_exclude_from_minify:css filter

Did this answer your question?