• Resolved blackfire0

    (@blackfire0)


    My own scripts on my site are loaded after external scripts. I load all of them using the wp_enqueue_script function and specify the dependencies. However, when I enable script aggregation in Autoptimize, my own scripts are loaded before the external ones. How can I preserve the original order? Any solution would be fine, including writing a custom plugin to address the issue.

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

    (@optimizingmatters)

    Aggregating is done long after assets are enqueued and only takes the exclusions (configured and some hardcoded) into account I’m afraid.

    So looking at your HTML source, are your own scripts aggregated or do they remain separate?

    Thread Starter blackfire0

    (@blackfire0)

    Aggregated. This part is very well.

    Before aggregate like:
    <link theme.css>
    <link angular.min.css> (external)
    <link myscript1.css>
    <link myscrip2.css>

    After aggregate like:
    <link autoptimize_xy.css>
    <link angular.min.css>

    Thread Starter blackfire0

    (@blackfire0)

    External: add_filter(‘wp_enqueue_scripts’, [$this, ‘loadScriptsFirst’], 0);
    My script: add_filter(‘wp_enqueue_scripts’, [$this, ‘loadScriptsLast’], 100);

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    aha, an external file, AO indeed cannot aggregate those. what you could to is change the “injection point” for CSS with below code snippet;

    add_filter( 'autoptimize_filter_css_replacetag', 'blackfire_override_css_replacetag', 10, 1 );
    function blackfire_override_css_replacetag($replacetag) {
      return array( '</head>', 'before' );
    }

    hope this helps,
    frank

    Thread Starter blackfire0

    (@blackfire0)

    Its worked, thanks!

    Plugin Author Optimizing Matters

    (@optimizingmatters)

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.