CMS Development

AKoprivec
参加者

Using external CDN's to import script into module

解決

Hi,

as the title says, I'm trying to you an external CDN (cdnjs) to import gsap into a module and use it in the js. Ive tried using requier js tags and adding it in the modules html but that doesn't seem to work. Is there any fix for this or is it just not possible to import?

 

Here is the code for both

 

'

{% require_js %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js" integrity="sha512-H6cPm97FAsgIKmlBA4s774vqoN24V5gSQL4yBTDOY2su2DeXZVhQPxFK4P6GPdnZqM9fg1G3cMv5wD7e6cFLZQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/Flip.min.js" integrity="sha512-aW9AOex6eTI5fwQAtEuIAd7wHW0xgm/OzRnw5+UZ49RMCRKIyEdf2SLoxQ4STMx0NoX9wIBXLlruAog9ZTzrSQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

{% end_require_js %}

'

and this is in the modules js

gsap.registerPlugin(Flip);

 

...

const state = Flip.getState(activeItem);
Flip.from(state, {
duration: 0.5s,
absolute: true,

});

....

0 いいね!
1件の承認済みベストアンサー
BarryGrennan
解決策
トップ投稿者

Using external CDN's to import script into module

解決

You're using require_js correctly. If you view page source you'll see it there in the footer. Your issue is that by putting the rest of the code in the module js it's being executed before your libraries are loaded, check your console you'll see it says gsap is not defined.

 

Put it all in the require_js and you should be good. The gsap not defined error goes away.

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

元の投稿で解決策を見る

0 いいね!
2件の返信
BarryGrennan
解決策
トップ投稿者

Using external CDN's to import script into module

解決

You're using require_js correctly. If you view page source you'll see it there in the footer. Your issue is that by putting the rest of the code in the module js it's being executed before your libraries are loaded, check your console you'll see it says gsap is not defined.

 

Put it all in the require_js and you should be good. The gsap not defined error goes away.

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

0 いいね!
AKoprivec
参加者

Using external CDN's to import script into module

解決

Aa thank you that fixes it yes. Is there any other way to do this, it doesn't seem like good practice ti have a lot of js code inside the html file or is this the only way to solve this in hubspot

0 いいね!