Recommended workflow for using GSAP / third-party JavaScript libraries? #325
Replies: 2 comments
|
Getting GSAP (and particularly ScrollTrigger) working in modern static site tools and bundlers can definitely be tricky if you hit lifecycle timing issues or scoping problems. Here is a breakdown of what is likely going wrong and the recommended workflow to get GSAP running cleanly in Instatic. The Core Problem: Why GSAP Might Be Failing right now Timing/DOM Readiness: Your JS file executes before the HTML elements exist in the DOM or before the layout engine finishes rendering. Missing Plugin Registration: ScrollTrigger is loaded or imported, but gsap.registerPlugin(ScrollTrigger) wasn't called before running the animation code. Recommended Workflows Install or Import via ESM: import { gsap } from "gsap"; // ALWAYS register the plugin first Wrap initialization in a DOM / Mount check: function initAnimations() { // Run on load Method 2: Global Script Loading (CDN / Head Tag) Add scripts to Head / Footer: Access via window.gsap in your runtime script: window.addEventListener("DOMContentLoaded", () => { // Your animations here... Answers to Your Specific Questions Is there a global Head or Layout file where external scripts should be loaded? Should third-party libraries always be imported through TypeScript modules? Key checklist for ScrollTrigger specifically: Did you call gsap.registerPlugin(ScrollTrigger)? If the page uses dynamic visual components or image loading, call ScrollTrigger.refresh() after the DOM finishes rendering to recalculate scroll positions. |



Uh oh!
There was an error while loading. Please reload this page.
Hi!
First of all, I really like the direction of Instatic. I'm currently evaluating it as an alternative to Webflow for my client work.
I'm trying to import an existing website that uses GSAP and ScrollTrigger.
In a normal HTML project I would either include GSAP using CDN script tags or import it through npm/TypeScript.
Inside Instatic I'm not sure what the recommended workflow is.
So far I have tried:
Adding the GSAP CDN script tags.
Creating a runtime .ts script.
Using ES module imports.
Importing from esm.sh.
Unfortunately I haven't been able to get GSAP working, and I can't find any documentation describing the recommended approach.
My questions are:
What is the recommended way to use external JavaScript libraries such as GSAP?
Is there a global Head or Layout file where external scripts should be loaded?
Should third-party libraries always be imported through TypeScript modules?
If npm imports are the preferred solution, how should packages be installed and resolved inside an Instatic project?
Is there an example project demonstrating the recommended way to use GSAP (or another third-party JavaScript library)?
One of the main reasons I'm interested in Instatic is the ability to import existing HTML/CSS/JS websites and continue editing them visually.
At the moment, understanding the recommended workflow for external JavaScript libraries is the only thing preventing me from moving forward.
Thanks in advance!
All reactions