• Resolved Grzegorz.Janoszka

    (@grzegorzjanoszka)


    Hi,

    I’m very satisfied with Autoptimize. Recently I started to check how many different css and js files were in use and I saw one css file for any page/post on my site and three different js files. The differences between the js files were tiny and were because of two small js files being added to some pages. I have added them (coma-separated) to the option “Exclude scripts from Autoptimize:”, but it didn’t have any effect – they are still aggregated.

    My options for js are:
    optimize js code: yes
    aggregate: yes
    aggregate inline: no
    force js in head: no
    exclude scripts: mediaelement-and-player.min.js,wp-mediaelement.min.js,comment-reply.min.js,top-10-tracker.js
    add try-catch: no

    the scripts comment-reply.min.js and top-10-tracker.js still are aggregated and I can’t get rid of them.

    I think it will be better for my site to use just one autoptimized js for everything with just 2 extra files added (when they are needed).

    Any thoughts of that? Thank you one more time for such a great plugin!

    The page I need help with: [log in to see the link]

Viewing 8 replies - 16 through 23 (of 23 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    not having top-10 require jquery would be the better solution though ??

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    I’m trying. What do I put in the autoptimize_filter_js_movelast filter? Is it the script handle?

    So when the original call is:

    wp_enqueue_script( 'tptn_tracker', plugins_url( 'includes/js/top-10-tracker.js', TOP_TEN_PLUGIN_FILE ), array( 'jquery' ), false, true );

    I have to include:

    
    function my_ao_override_movelast($movelast) {
            $movelast[]="tptn_tracker";
            return $movelast;
    }

    Right?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Or maybe the other way around. Can AO take an external JS and put it inline? ??

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    What do I put in the autoptimize_filter_js_movelast filter? Is it the script handle?

    I would use part of the path/ filename, so top-10-tracker.js

    Can AO ake an external JS and put it inline?

    anything can be done with the API if you really want to, but nope, not out of the box and not with a simple filter ??

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    well, the trick autoptimize_filter_js_unmovable and autoptimize_filter_js_movelast didn’t work. Thank you for your efforts. Luckily the author of the top-10 plugin thinks it is a good idea to have the JS loaded on every page, so I hope with the new version of top-10 plugin I will have only one common aggregated AO js for any request. So far I have reduced this number from 3 to 2, but I will try to use WP API to dequeue top-10 js and put it inline. The problem I have all my inline JS is before AO, but I will try to put it after.

    Thank you one more time for an excellent support.

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Last question, I promise. I put stuff using wp_footer with priority PHP_INT_MAX and still AO beats me and puts its stuff later. How can I put something after AO aggregated js in the footer?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Ah, but that’s because AO uses the output buffer to capture the full HTML and works on that. what you could do is change the JS injection point using something like this;

    add_filter('autoptimize_filter_js_replacetag','override_js_replacetag',10,1);
    function override_js_replacetag($replacetag) {
            return array("<injectjs />","replace");
    }

    “replace” can also be “before” or “after” and in case of above example you would need to ensure that <injectjs /> is present in the footer.

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    It is so awesome! Thank you! ??

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Exclude scripts from Autoptimize not working’ is closed to new replies.