• 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 15 replies - 1 through 15 (of 23 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    that’s pretty weird, it should just work … any errors in the PHP errorlog?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    No, I have PHP7.2 and the error log is almost empty. Nothing regarding AO.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    no idea, afraid the only way to troubleshoot would be to add debug logging to the autoptimizeScripts.php.

    except … do you have database/ object caching (redis/ memcached)? if so, can you try purging that?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    I use acpu object cache, I have cleared it, waited 12 hours and it is still the same.

    I think it is very simple to replicate. If you have a wordpress and add the same options as I have, will comment-reply.min.js be aggregated or not?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    I just thought – can any filters override the setting? I have such filter:

    add_filter(‘autoptimize_filter_js_exclude’,’pushJQuery’);
    function pushJQuery($in) {
    if (strpos($in,”js/jquery/jquery.js”)!==false) {
    $jQurl=includes_url(“js/jquery/jquery.js”);
    header(‘Link: <‘.$jQurl.’>; rel=preload; as=script’,false);
    }
    }

    Can it mess with the setting?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    I think I can answer myself – I think it was that filter messing up and blocking the config option. Once the cache will clear I will be able to confirm, but it looks everything is all right now.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    is can and will, as the filter does not return $in πŸ™‚

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Hi, I am reopening this thread as something is definitely wrong.

    I wanted to exclude two scripts: comment-reply.min.js and top-10-tracker.js. The first one is OK – it is in the page source to download it and execute. The second one is, but not called directly – it is hiding as autoptimize_single_[XYZ].js – this js is identical to the file top-10-tracker.js, but for some reason the tracking stopped working. The requests are not coming.

    When I removed top-10-tracker.js from the exclude config, it is aggregated within one big autoptimize js bundle and it is working OK – I get tracking call after every page view, even from the cache.

    So, why excluding two scripts makes autoptimize calling one directly and copying the other to autoptimize_single file which somehow breaks it?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    AO (starting at v2.4) will minimize non-aggregated files that are not minified (based on filename having min. in it).

    You can disable that functionality with this code snippet;

    
    add_filter('autoptimize_filter_js_minify_excluded','__return_false');

    hope this clarifies πŸ™‚
    frank

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Actually I am not sure if “min.” in filename is good as the only criterium. Maybe you can check the file size before and after minification, to see whether it makes any sense?

    Anyway, I think I know where the problem is. The tracking script uses jquery and it is placed in head, while autoptimized js (which includes jquery) is loaded at the end of th epage. That’s why it is not working. So yet again, it is not AO bug πŸ™‚

    Thank you for your outstanding support!

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Actually I am not sure if β€œmin.” in filename is good as the only criterium. Maybe you can check the file size before and after minification, to see whether it makes any sense?

    that would require AO to minify, which is the most costly operation AO does, which is why I’m trying to avoid minifying in the first place πŸ™‚

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Well, interestingly, the comment I placed here last week is gone. There is actually a problem with AO.
    When you enqueue a script, you can add its dependencies. I have a script top-10-tracker.js which relies on jquery. Auotptimize takes care of jquery, aggregating it with anything else and top-10-tracker.js is in AO config to be not touched and left alone
    As the result the dependency is broken. In the HTML I see that the page tries to load first top-10-tracker.js and then autoptimized js with jquery in it. Of course top-10-tracker.js doesn’t work then at all.
    It seems AO breaks the dependency. Is there anything you could do about that?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    AO does not (and has never) know(n) or care(d) about how JS (or CSS) is enqueued Gregorz, it’s all a matter of excluding what needs to be excluded and in your case you’ll have to also exclude jquery.js from being aggregated/ optimized πŸ™‚

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Probably, but it beats the whole purpose of AO πŸ™‚
    Is there a way to have autoptimized js to be loaded as the first one and any other js (like the ones excluded in the config) later on? I can’t achieve that.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    this is the right window/ tab/ topic;

    hmm, you could try returning false to the autoptimize_filter_js_unmovable-filter and then add your top-10 script to the domovelast array using the autoptimize_filter_js_movelast filter?

    but do take into account that;
    a) this might break stuff
    b) the move(last) logic is old, off as per the filter and largely untested

    frank

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