Back to Top

Better WordPress Minify

Better WordPress Minify

This plugin relies on WordPress's enqueueing system to minify your JS and CSS files, also provides friendly minify urls and CDN support.

Q: Some or all minify strings result in 404 error

There can be many causes for this issue, and below are the three most common ones:

Cause 1: You don’t have a correct Document Root. Check out this section in the official documentation for more details.

Cause 2: Your minify strings are too long. Certain servers have a size/length limit applied to any request url. If you’re not using Friendly Minify Url feature, chances are you will encounter a 404 Not Found or 500 Internal Server Error for strings that contain more than 10 files.

To minify fewer files per minify string, go to BWP Minify > General Options > Plugin Functionality > set “One minify string will contain” setting to a lower number (e.g. 10, 7, 5, etc.)

Related support topic: http://wordpress.org/support/topic/images-gone-when-usi ... replies=10

Cause 3: This actually relates to Cause 2. When you minify too many files in one string, the request could result in a timeout and thus return an error instead of minified contents. You can try the same solution in Cause 2 to solve this.

Q: I keep getting 404 not found error for friendly Minify urls?

First you need to make sure that your server config files are properly updated with BWP Minify’s rewrite rules.

If you are using the Apache web-server, the updated rewrite rules should be found in following files:

  • The cache directory‘s .htaccess file, you should see something similar to # BEGIN BWP Minify Rules ... # END BWP Minify Rules
  • (only when you’re on sub-directory multi-site environment) Your WordPress’s .htaccess file, which is usually located in the same directory as your index.php. You should see something similar to # BEGIN BWP Minify WP Rules ... # END BWP Minify WP Rules

If you are using the Nginx web-server, BWP Minify rewrite rules must be added to the server { .. } block where you define your WordPress’s virtual host. It is highly recommended that you put BWP Minify’s rules directly above your cache plugins’ rules and above WordPress’s rewrite rules on a sub-directory multi-site environment, as shown here.

If rewrite rules are not found, you will have to re-add them, either manually (if server config files are not writable) or automatically by visiting any BWP Minify’s admin page. When enabling friendly Minify urls feature, if your server config files are not writable, you should see error regarding so, and rewrite rules will be printed on-screen so you can grab them and update the rules yourself.

Related support topic: http://wordpress.org/support/topic/404-for-combined-and ... ?replies=1

Q: I see this error message on Advanced Options page: “BWP Minify was not able to auto-detect friendly url based on your current cache directory.” What does that mean?

You are using Friendly Minify urls feature, and this notice warns you that friendly Minify urls can’t be auto-generated, and as such no friendly urls can be served (regular ones will be used instead). This is mostly due to the cache directory being either not found, or not publicly accessible via the current domain.

Check your cache directory and make sure it is accessible via a web browser, or set a custom Friendly Minify url path that points to a publicly available cache directory. See the official documentation for more details.

Q: I see some JS error such as “google is not defined” when I enable Minify JS automatically

Most of the time this is caused by an enqueued file that is moved from its original position but the codes that depend on such file still stay there. There are two possible solutions:

1. If the enqueued file is external (e.g. google map JS api), you can enable this setting “Leave external files at their original positions?” under BWP Minify > General Options OR go to BwP Minify > Manage Enqueued Files and allow such file to stay at its original position.

2. Ask the developer of the plugin/theme that enqueues such file and suggest him/her using a document ready callback to run the needed JS functions. For example:

/** instead of this **/
my_JS_function();
/** Use this **/
jQuery(document).ready(function() {
    my_JS_function();
});

Q: My site looks good in all browsers except Firefox when Minify CSS is enabled

There’s a specific issue with Firefox when minifying CSS file: if you use -ms-filter CSS rule in any of your CSS file, you will need to remove the quotes for Firefox to work. For example you will have to replace this:

-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='link-to-image',sizingMethod='scale')"; 

with this:

-ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='link-to-image',sizingMethod='scale'); 

More information can be found in the next question.

Q: My site appears broken if I enable Minify CSS automatically

There are edge cases when minified CSS become invalid and can not be used to render pages on your website. Such behaviour vary from browsers to browers, for example your site might still look fine on Chrome, but not on Firefox, and vice versa. Take a look at this support topic on wp.org, to understand the weirdness of this issue.

The best thing you can do is to figure out which CSS file is causing issue, and then choose to ignore (not minify) it. To ignore a CSS file, go to BWP Minify > Manage Enqueued Files > search for the filename > click on Select and choose Ignore > press Save changes.

You can try adding a few files to the ignored list and see if your site looks fine after that, keep narrowing down the list and eventually you will be able to find the offending CSS files. After that you should try to put the troublesome CSS files into Scripts to be minified and printed separately position first, and if that fails, select to completely ignore them.

Note that this question might as well apply to JS files.

Q: I keep getting notices and/or errors stating that some directories or config files are not writable, what should I do?

Minify uses a config file to function, so settings you choose on BWP Minify > General Options page must be saved to that config file. If the config file is not writable, you will see an error indicating so, and its auto-generated contents will be printed on-screen for you to update it manually. More info here.

The default functionality of Minify will perform better if your cache directory is writable, so BWP Minify will warn you if such directory is not. Try changing the permission of the cache directory to 777 if you encounter such issue (your favorite FTP client should help you with this). If 777 is not an option for you, you can safely ignore the warning because Minify still works without having the cache directory writable.

The friendly Minify urls feature rely on rewrite rules that are written to your server’s config files, be it Apache’s .htaccess file or Nginx’s .conf file. Once again, if rewrite rules can not be automatically updated, errors will be shown and you will be given the choice to manually update. On Apache web-servers, friendly Minify urls will be turned off automatically if required rewrite rules are not found to prevent your site from breaking. On Nginx web-servers, however, it’s your duty to make sure that required rewrite rules are in place. Note that this feature requires your cache directory to be writable as well.

Q: What happens if plugins or themes echo the JS and CSS files directly?

A: Then this plugin won’t be able to minify them, but there are two workarounds you can use:

– Manually enqueue JS and CSS files, preferably in your (child) theme’s functions.php, something like this:

add_action('init', 'my_enqueue_function');
function my_enqueue_function()
{
    wp_enqueue_style('style');
}

Make sure you disable/remove the original JS/CSS files that are printed directly, so you don’t end up with two instances of same files.

– Put some custom rewrite rules in .htaccess file. If you use nice permalinks, WordPress should have created a .htaccess file in your root directory, otherwise just use your web host’s file manager to create one, and then add the following to it:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^path-to-unenqueued-js-file/(.*\.js) /path-to-min-folder/?f=path-to-unenqueued-js-file/$1 [NC,L,QSA]
</IfModule>

Q: How do I get help for this plugin?

A: Please comment on the latest release article. Thanks!

… (any question that might benefit others will appear here)

Print Article Plugin Update Feed