Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:57:05+00:00 2026-06-10T17:57:05+00:00

I’m writing a script that’s meant to be embedded on 3rd party sites to

  • 0

I’m writing a script that’s meant to be embedded on 3rd party sites to add functionality to them. I recently ripped out my rather messy custom loader code and started replacing it with requirejs. One of the libraries that optionally gets loaded for me (depends on some parameters passed in) is jQuery.

This works well, until my script is included on a page that jQuery is already on, in which case, what appears to happen is some plugins partway load, requirejs loads jQuery over the page’s version, and the plugins promptly break.

Asking clients to rewrite their pages just to use this script is out of the question, so what I would like to do is detect if jQuery is already loaded, if it is, skip loading it through requirejs, and just use the already loaded one (This will possibly open me up to odd edge cases and bugs when they’re using a much older version of jQuery, but I don’t have much choice).

What I thought I would do is write a new module, that would first see if jQuery is loaded, if it is, just export the jQuery object, if it’s not, then load it, then do the export. However, I appear to be stymied, as the definition function for the module appears to need to be synchronous to work, so I can’t go off and load another script, which would be asynchronous, then stuff the export into requirejs.

Am I missing something in the docs? Is what I’m attempting impossible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:57:07+00:00Added an answer on June 10, 2026 at 5:57 pm

    I had the same issue on a similar project, using require.js for a library intended to be loaded on 3rd-party sites. You can see my approach here, but here’s the simplified version:

    // check for existing jQuery
    var jQuery = window.jQuery,
        // check for old versions of jQuery
        oldjQuery = jQuery && !!jQuery.fn.jquery.match(/^1\.[0-4](\.|$)/),
        localJqueryPath = libPath + 'jquery/jquery-1.7.2.min',
        paths = {},
        noConflict;
    
    // check for jQuery 
    if (!jQuery || oldjQuery) {
        // load if it's not available or doesn't meet min standards
        paths.jquery = localJqueryPath;
        noConflict = !!oldjQuery;
    } else {
        // register the current jQuery
        define('jquery', [], function() { return jQuery; });
    }
    
    // set up require
    require.config({
        paths: paths 
    });
    
    // load stuff
    require(['jquery', ... ], function($, ...) {
    
        // deal with jQuery versions if necessary
        if (noConflict) $.noConflict(true);
    
        // etc
    
    });
    

    As you can see, this looks for jQuery, and then either defines the “jquery” module as a wrapper for the existing library, or (if there’s no jQuery or if the existing jQuery is an old version) loads the library-specific jQuery with noConflict.

    This works pretty well. The only downside is that you’re calling require() dynamically within your script, which makes it more difficult to use the r.js optimizer effectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.