Title: Load plugin scripts first!
Last modified: August 30, 2016

---

# Load plugin scripts first!

 *  Resolved [Mironomadic](https://wordpress.org/support/users/mironomadic/)
 * (@mironomadic)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/)
 * Hi,
 * First of all, thanks for a great plugin!
 * We have a speed issue on a site using the Nelio plugin. That is requests are 
   being called twice, now the Nelio js script are loading last which explains why!
 * I am trying to move the Nelio scripts to load first as advised. I have tried 
   using a function, this plugin [https://wordpress.org/support/plugin/plugin-organizer](https://wordpress.org/support/plugin/plugin-organizer)
   and this one [https://wordpress.org/plugins/re-order-css-and-js-loading-order/](https://wordpress.org/plugins/re-order-css-and-js-loading-order/)
   with no luck!
 * There seems something forcing them to be last in the list!
 * Could you please advice or better provide me a code snippet to get this done?
 * Thanks
 * [https://wordpress.org/plugins/nelio-ab-testing/](https://wordpress.org/plugins/nelio-ab-testing/)

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

 *  Thread Starter [Mironomadic](https://wordpress.org/support/users/mironomadic/)
 * (@mironomadic)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672373)
 * Also tried by renaming the plugin with a @ character for first letter, this only
   moved up the plugin location in the backend sidebar 🙂
 * I found this function and tried it:
 * add_action( ‘activated_plugin’, ‘nelio_load_first’ );
    function nelio_load_first(){
   $path = str_replace( WP_PLUGIN_DIR . ‘/’, ”, __FILE__ ); if ( $plugins = get_option(‘
   active_plugins’ ) ) { if ( $key = array_search( $path, $plugins ) ) { array_splice(
   $plugins, $key, 1 ); array_unshift( $plugins, $path ); update_option( ‘active_plugins’,
   $plugins ); } } }
 * Still no luck!
 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672415)
 * Hi!
 * I think I know what might be amiss. If you go to `includes/controller.php`, line
   317, you’ll see the following piece of code:
 *     ```
       add_action( 'wp_enqueue_scripts',
          array( &$this, 'load_tracking_script' ), 99 );
       ```
   
 * The priority of the hook should be changed from `99` to `1`:
 *     ```
       add_action( 'wp_enqueue_scripts',
          array( &$this, 'load_tracking_script' ), 1 );
       ```
   
 * As stated in the [Codex](https://codex.wordpress.org/Function_Reference/add_action#Parameters):“
   Lower numbers correspond with earlier execution”.
 * I’ll apply the change in the next release of our plugin, so that your changes
   are kept when updating the plugin.
 * Let me know if this helped!
 *  Thread Starter [Mironomadic](https://wordpress.org/support/users/mironomadic/)
 * (@mironomadic)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672418)
 * Thanks for the quick reply! Am trying NOW
 *  Thread Starter [Mironomadic](https://wordpress.org/support/users/mironomadic/)
 * (@mironomadic)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672421)
 * No luck…Had to bring it back priority to 99!
 * The script disappeared for logged in users!
 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672422)
 * My bad! Here’s what you have:
 *     ```
       add_action( 'wp_enqueue_scripts',
          array( &$this, 'register_tracking_script' ) );
       add_action( 'wp_enqueue_scripts',
          array( &$this, 'load_tracking_script' ), 99 );
       ```
   
 * And here’s what you should have:
 *     ```
       add_action( 'wp_enqueue_scripts',
          array( &$this, 'register_tracking_script' ), 1 );
       add_action( 'wp_enqueue_scripts',
          array( &$this, 'load_tracking_script' ), 1 );
       ```
   
 * Before loading the script, we need to register it 😛 Try this and let me know
   if it worked 🙂
 *  Thread Starter [Mironomadic](https://wordpress.org/support/users/mironomadic/)
 * (@mironomadic)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672427)
 * Great!!! However, nelio script is ranking fourth.
 * jquery.js?ver=1.11.3
    jquery-migrate.min.js?ver=1.2.1 widget-groups.min.js?ver
   =2.3.4 6657419267538944.js?ver=4.2.10
 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672432)
 * Well, that’s normal. `jquery` and `jquery-migrate` are required by our script(
   that’s why they appear before), and `6657419267538944.js` is one of our scripts(
   which is also a requirement of our `tracking.min.js`).
 * The only script that could appear after Nelio’s is `widget-groups.min.js`, but
   in order to do that, you’ll probably have to edit some other plugin (or your 
   theme). In my opinion, if it’s only one script, it doesn’t really matter.
 * How are things working now? Is it faster?
 *  Thread Starter [Mironomadic](https://wordpress.org/support/users/mironomadic/)
 * (@mironomadic)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672492)
 * Sorry for the late reply but It was around 5am for me and i had stayed all day
   and night, so I hit the bed after the last upgrade!
 * Yes true, jquery are essential no complaining 🙂
 * Before the Nelio move I had already brought speed down by heavily cleaning up
   the database tables (the was a little frustrating because for many tables it 
   is hard to identify the related script and we would not want to delete a running
   script table but was able to do so by searching wp-content with regex), there
   was a lot of deleted plugins left overs, and that significantly reduced the number
   of request from around 200 to around 50!
 * Then I also disabled unnecessary plugin from loading on pages when not needed,
   that did some magic! At this point speed was reduced about 5s.
 * Then came the Nelio move which gained us around 2s speed, so the speed objective
   was accomplished.
 * Thank you very much for your amazing support, well done and best of luck!
 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672528)
 * I’m glad to hear!
 * Have a wonderful day (or night)!
 * And, remember, if there’s anything else I can do for you, just let me know; I’ll
   be happy to help.

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

The topic ‘Load plugin scripts first!’ is closed to new replies.

 * ![](https://ps.w.org/nelio-ab-testing/assets/icon-256x256.png?rev=2514600)
 * [Nelio A/B Testing – AB Tests and Heatmaps for Better Conversion Optimization](https://wordpress.org/plugins/nelio-ab-testing/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nelio-ab-testing/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nelio-ab-testing/)
 * [Active Topics](https://wordpress.org/support/plugin/nelio-ab-testing/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nelio-ab-testing/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nelio-ab-testing/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [David Aguilera](https://wordpress.org/support/users/davilera/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/load-plugin-scripts-first/#post-6672528)
 * Status: resolved