We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to know when a script (jQuery) is already included by another Extension?

Development and Programming

Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

I’ve been doing a few extensions lately that require jQuery. If I have 3-4 of these extensions all installed at once, and they all have a setting to locate your jQuery file, doesn’t that get hit 3-4 times? There’s a couple new ones I want to release, but not until I figure out how to keep these lean.

What’s the best practice way to check if a script has already been called on the page? I want these extensions to say “Is there a reference to jQuery yet? If not, then use the path established in your settings to find it”.

       
Jesse M's avatar
Jesse M
92 posts
17 years ago
Jesse M's avatar Jesse M

Perhaps you’d be interested in this thread.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

Thanks for pointing me over there. That’s exactly the info I was looking for. Too bad there isn’t a real solution!

       
Arun S.'s avatar
Arun S.
792 posts
17 years ago
Arun S.'s avatar Arun S.

Ryan…

If you look towards at the end of the post that Jesse linked to, you’ll see a link to an article about the Google AJAX API. I think that’ll do what you’re asking for here.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Oh Oh Me Me!!!!!

What about?

if (typeof jQuery != 'undefined'){
script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'jquery.js';
document.getElementsByTagName('head')[0].addChild(script);
}

I haven’t tested it but I’m sure it would work. You may have issues wit different versions of jQuery still

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.