Jump to content
Search Community

Multiple instances of GSAP

MethodNerd test
Moderator Tag

Recommended Posts

I'm writing a script that will be included on other websites that I don't have control over. I'm trying to figure out the best way to make sure the use of GSAP in my script doesn't conflict with the possible use of any version or multiple versions of GSAP that a site is already using or may use in the future.

 

I found a proposed solution from 2016 at:

 

It recommends:

 

  1. Storing window.GreenSockGlobals and a couple of other global variables in temporary variables.
  2. Setting some of the variables to null.
  3. Assigning window.GreenSockGlobals to a custom variable as an empty object for use inside my script.
  4. Loading the GSAP version my script will use.
  5. Restoring the affected variables to their original versions for other scripts to use.

 

I notice when inspecting the window object that window.GreenSockGlobals has not been used since GSAP 3.0. I also noticed that GSAP is using between 30 and 53 global variables depending on the version you use. Some of those variables with the same name contain different values depending on the version of GSAP you use.

 

Should I be checking for the existence of all possible GSAP global variables, storing them, and reassigning them like in the example above?

 

Or do you have any other suggestions on how to go about making sure the use of GSAP in my script doesn't conflict with any other scripts using GSAP on the same page?

Link to comment
Share on other sites

Thanks for pointing that out.
 
In a scenario such as:
 
If I'm not using ES modules and I'm using GSAP 3x with plugins for my script, and I'm not sure what version of GSAP the site might be using and if they might be using plugins in their scripts.
 
Do I need to store, reset, and restore window._gsDefine and window._gsQueue like in the example at:
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...