Home>Support>Loading jquery twice issue

Loading jquery twice issue

I would like to disable the load of jQuery when it comes to the page that SiteOrigin is in action. In my case, there is an issue when loading:

Sourcing the world’s best oysters

because its loading twice jQuery.

How can i prevent SiteOrigin to load jquery?

Thanks!

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 3 years, 11 months ago Andrew Misplon
    Hi, I Work Here

    Hi David

    Thanks for reaching out.

    Have you made progress since posting? I’m only seeing jQuery loaded once on the linked page.

  2. 3 years, 11 months ago davidpenuela

    Hi Andrew,

    in my header-bundle.js i have jquery and its only in the link that i send that is added jquery and other scripts at the bottom of the page (if you see the source code of the home vs the one from the entry with SiteOrigin plugin, you can see that its added the extra jquery). So my idea is to disable that jquery with a hook/action?

    Thanks!

  3. 3 years, 11 months ago Andrew Misplon
    Hi, I Work Here

    Thanks for the update.

    Is the duplicate jQuery file visible in the source code of the page in question? I can only see jQuery being loaded once on line 438.

    If you use view-source:https://www.darbys-london.com/journal/oyster/ in your address bar the line numbers will be listed.

  4. 3 years, 11 months ago davidpenuela

    Hi Andrew,

    yeah, that one is the one i want to remove from loading since i am already loading jQuery in line 11 (header-bundle.js?ver=5.2.6 is loading in one file multiple libraries).

    Is that possible? can i prevent with a hook in functions.php SiteOrigin to add the jQuery at the end of the document?

    Thanks!

  5. 3 years, 11 months ago Andrew Misplon
    Hi, I Work Here

    Thanks.

    Page Builder loads jQuery by specifying jQuery as a dependency. You could do the same by listing jQuery as a dependency when enqueuing your theme’s JS file. Doing so would ensure the core WP jQuery version is used on other pages. Here is an example of that: https://github.com/siteorigin/siteorigin-corp/blob/develop/functions.php#L194
    Ref: https://developer.wordpress.org/reference/functions/wp_enqueue_script/
    Doing it this way might avoid potential issues in the future.

    Page Builder’s dependency is declared as follows https://github.com/siteorigin/siteorigin-panels/blob/1f2b6e76a4d5559c114a115d18c865b946b732f9/inc/styles.php#L54.

    You can perhaps try something like:

    function remove_jquery() {
        wp_deregister_script( 'jquery' );
    }
    add_action( 'wp_enqueue_scripts', 'remove_jquery' );

    Ideally, the function should be namespaced, for example instead of remove_jquery, if this were in SiteOrigin Corp theme we’d use siteorigin_corp_remove_jquery.

  6. 3 years, 11 months ago davidpenuela

    Perfect Andrew! I will check this action you mention, i think is what i was looking for.

    Thank you very much for your help!

  7. 3 years, 11 months ago Andrew Misplon
    Hi, I Work Here

    Sure, no problem, let us know how it goes.

  8. 3 years, 11 months ago davidpenuela

    Andrew!

    When adding the action, it also removes some other scripts, for example the one from the player that makes it responsive.

    <script type='text/javascript' src='http://127.0.0.1:3020/wp-includes/js/mediaelement/mediaelement-and-player.min.js?ver=4.2.13-9993131' id='mediaelement-core-js'></script>
    <script type='text/javascript' src='http://127.0.0.1:3020/wp-includes/js/mediaelement/mediaelement-migrate.min.js?ver=5.5.1' id='mediaelement-migrate-js'></script>
    <script type='text/javascript' id='mediaelement-js-extra'>
    /* <![CDATA[ */
    var _wpmejsSettings = {"pluginPath":"\/wp-includes\/js\/mediaelement\/","classPrefix":"mejs-","stretching":"responsive"};
    /* ]]> */
    </script>
    <script type='text/javascript' src='http://127.0.0.1:3020/wp-includes/js/mediaelement/renderers/vimeo.min.js?ver=4.2.13-9993131' id='mediaelement-vimeo-js'></script>
    <script type='text/javascript' src='http://127.0.0.1:3020/wp-includes/js/mediaelement/wp-mediaelement.min.js?ver=5.5.1' id='wp-mediaelement-js'></script>
    <script type="text/javascript">document.body.className = document.body.className.replace("siteorigin-panels-before-js","");</script></body>
    

    Any suggestions?

  9. 3 years, 11 months ago Andrew Misplon
    Hi, I Work Here

    Hi David

    Thanks for your feedback.

    We’re a bit beyond our normal free support scope with this task. Is the version of jQuery in your theme JS file different from the core version? Are you sure you don’t want to enqueue your theme JS file with jQuery as a dependency? It would sort this all out.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More