Problem with Javascript Minification

I'm trying to compress all of my CSS and JS to reduce my site's size and increase performance, however when I select JS to be minified, it breaks Appointments+. Can you guys look into fixing this for a future version? I'm using the plugin Autoptomize for minification.

  • Vinod Dalvi

    Hi Chris,

    I hope you are well today and thanks for posting on the forum.

    Could you please tell me specifically what is breaking in Appointments+ when you minimize the JS?

    There are various JS files in the Appointments+ directory but many of them are standard library files so i want to know specifically which one is causing the issue.


    Please advise.

    Kind Regards,
    Vinod Dalvi

  • Chris

    The problem seemed to be when selecting a service. I have the autorefresh option turned on, so when the site isn't minified, the "Show Available Times" button disappars and changing the selection refreshes the page. However when it's minified, that button never goes away and you can't see the times even when clicking that button. Clicking the days on the calendar itself worked most of the time, but seemed kind of finnicky and clicking on the times took a few tries, but it did eventually open the form to book the time, however it seemed extremely slow. I'd suggest just loading the two plugins on a test site and seeing what happens.

  • Ash

    Hello @Chris

    This is the limitation of Autoptimize plugin, not appointments plugin. Any plugin that will print script using wp_head or wp_footer hook will not work with Autoptimize plugin.

    The plugin adds the javascript at the very bottom of the site. So if any js script is called before that, won't work. And in appointments plugin, some standard third party libraries are used and we can't edit those libraries. So, I am afraid, we don't have any way to customize this to make compatible with Autoptimize plugin. You have to disable javascript minification I am sorry.


  • Ash

    Hello @Chris

    Well, maybe I have used wrong wording.

    That's definitely not true as Autoptomize works with WooCommerce and several other plugins that put JS in the head or footer

    "put JS in the head or footer" - there are two ways to put a script. Using wp_enqueue_script method (it can be either in footer or header) and using wp_head(header)/wp_footer(footer) method.

    The autoptimze plugin minimizes the scripts that uses wp_enqueue_script method. But when the script is put using wp_head or wp_footer, it is not minimized. For some custom scripts we needed to print the script using wp_footer method. As autoptimize prints all minimized js as the last line and wp_footer prints before that, so the error comes. This is the limitation for now.

    I am marking this as a feature request if there is any way to print that script using wp_enueue_script method, but right I can't confirm you I am afraid.


  • Chris

    Hey Ash,

    To me, it just sounds like you guys used the improper method for adding scripts to the page as wp_enqueue_script has the ability to add scripts to the header or footer via its last parameter.

    After looking at the code, I see that it runs it using the wp_footer action in order to inject JS into a jQuery DOM ready function. I could see using this method if the user were to be putting custom JS on the page via an admin meta box, but I don't think that's an option. Why exactly is it done this way since even add-ons can use wp_enqueue_script?

  • Ash

    Hello @Chris

    I hope you are well today.

    Well, there are lots of scripts used in appointments. In the plugin, user can change the script code outside of the plugin, that's why wp_footer is used.

    If wp_enqneue_script is used, then there was no way to make that script changeable. The logic is something like the following:

    $script = 'ALL JS CODE';
    add_action( 'wp_footer', 'add_script' );
    function add_script() {
      global $script;
      echo apply_filters( 'my_script', $script );

    But I have already marked this as a feature request to make it using wp_enqueue_script and sent a note to the developer.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.