MethodNerd Posted June 10, 2021 Share Posted June 10, 2021 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: Storing window.GreenSockGlobals and a couple of other global variables in temporary variables. Setting some of the variables to null. Assigning window.GreenSockGlobals to a custom variable as an empty object for use inside my script. Loading the GSAP version my script will use. 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 More sharing options...
OSUblake Posted June 10, 2021 Share Posted June 10, 2021 Hi @MethodNerd Check out this post. 2 Link to comment Share on other sites More sharing options...
MethodNerd Posted June 11, 2021 Author Share Posted June 11, 2021 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: https://greensock.com/forums/topic/15485-using-multiple-instances-of-greensock-on-the-same-page/?tab=comments#comment-67387 Link to comment Share on other sites More sharing options...
GreenSock Posted June 11, 2021 Share Posted June 11, 2021 10 hours ago, MethodNerd said: Do I need to store, reset, and restore window._gsDefine and window._gsQueue like in the example at: Those were only in old versions (2.x and earlier). They don't exist in v3. So no. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now