• Resolved MarcGuay

    (@marcguay)


    I am enqueuing the external Google Maps API with a callback to one of my JS scripts. The API is loading before the Autoptimize aggregate script and so it is failing to find the callback function. Is there a way to ensure the API script is added after? Or do I need to exclude the script with the callback and all of its dependencies? Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    best would be to use AO’s API to change the “injection point” of the aggregated JS, see below code example which assumes a comment <!-- injectjs /--> in the HTML (ideally footer) which will be replaced by the HTML for the aggregated JS;

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

    hope this helps,
    frank

    Thread Starter MarcGuay

    (@marcguay)

    Beautiful, works like a charm, thanks!

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    you’re welcome, feel free to leave a review of the plugin and support here! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Enqueue script after Autoptimize aggregate’ is closed to new replies.