Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLD-338-rendering-PGW #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

asad-rafter
Copy link
Contributor

No description provided.

Copy link
Collaborator

@yuval-cloudinary yuval-cloudinary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter I'm afraid that this is not in the right direction. This uses onload, but also dynamically injects the script ensuring it will be loaded much later than needed. This slows down the loading of the PGW which causes increases in the LCP.

window.cldProductGallery is not assigned in

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />

Could this be the issue?

@asad-rafter
Copy link
Contributor Author

@asad-rafter I'm afraid that this is not in the right direction. This uses onload, but also dynamically injects the script ensuring it will be loaded much later than needed. This slows down the loading of the PGW which causes increases in the LCP.

window.cldProductGallery is not assigned in

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />

Could this be the issue?

Yes, this is the issue. So the problem is, sometimes in milliseconds difference <script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" /> loads late and the cloudinary object from other scripts assigned to window.cldProductGallery, in that case it breaks the PGW because the script is not available in DOM. Let me know if you have any better solution for this

@yuval-cloudinary
Copy link
Collaborator

@asad-rafter I'm afraid that this is not in the right direction. This uses onload, but also dynamically injects the script ensuring it will be loaded much later than needed. This slows down the loading of the PGW which causes increases in the LCP.
window.cldProductGallery is not assigned in

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />

Could this be the issue?

Yes, this is the issue. So the problem is, sometimes in milliseconds difference <script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" /> loads late and the cloudinary object from other scripts assigned to window.cldProductGallery, in that case it breaks the PGW because the script is not available in DOM. Let me know if you have any better solution for this

@asad-rafter The new code adds loading time, and still allows such a condition. Please remove the onload changes and assign window.cldProductGallery after

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />
exactly like it is done in all other places you call the widget

@asad-rafter
Copy link
Contributor Author

asad-rafter commented Dec 17, 2024

@asad-rafter I'm afraid that this is not in the right direction. This uses onload, but also dynamically injects the script ensuring it will be loaded much later than needed. This slows down the loading of the PGW which causes increases in the LCP.
window.cldProductGallery is not assigned in

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />

Could this be the issue?

Yes, this is the issue. So the problem is, sometimes in milliseconds difference <script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" /> loads late and the cloudinary object from other scripts assigned to window.cldProductGallery, in that case it breaks the PGW because the script is not available in DOM. Let me know if you have any better solution for this

@asad-rafter The new code adds loading time, and still allows such a condition. Please remove the onload changes and assign window.cldProductGallery after

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />

exactly like it is done in all other places you call the widget

PGW is only called on PDP, where we are using the onload.
let's suppose we have added <script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" /> in isml template, then how would we know its loaded and now assign it and how can we assign cloudinary to window.cldProductGallery in isml

@yuval-cloudinary
Copy link
Collaborator

PGW is only called on PDP, where we are using the onload. let's suppose we have added <script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" /> in isml template, then how would we know its loaded and now assign it and how can we assign cloudinary to window.cldProductGallery in isml

@asad-rafter You'll add a script tag immediately following the above script tag, so it will look like this:

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />
<script>
window.cldProductGallery = cloudinary;
</script>

@asad-rafter
Copy link
Contributor Author

PGW is only called on PDP, where we are using the onload. let's suppose we have added <script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" /> in isml template, then how would we know its loaded and now assign it and how can we assign cloudinary to window.cldProductGallery in isml

@asad-rafter You'll add a script tag immediately following the above script tag, so it will look like this:

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />
<script>
window.cldProductGallery = cloudinary;
</script>

@yuval-cloudinary We were already using this and it was causing issue, that's why we change it on onload

@yuval-cloudinary
Copy link
Collaborator

PGW is only called on PDP, where we are using the onload. let's suppose we have added <script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" /> in isml template, then how would we know its loaded and now assign it and how can we assign cloudinary to window.cldProductGallery in isml

@asad-rafter You'll add a script tag immediately following the above script tag, so it will look like this:

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" />
<script>
window.cldProductGallery = cloudinary;
</script>

@yuval-cloudinary We were already using this and it was causing issue, that's why we change it on onload

@yuval-cloudinary
Copy link
Collaborator

@asad-rafter I don't think we had this way. Can you share a link to the previous time?

@asad-rafter
Copy link
Contributor Author

@asad-rafter I don't think we had this way. Can you share a link to the previous time?

@yuval-cloudinary
Copy link
Collaborator

Having this syntax is equivalent, do I don't mind it:

<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" onload="window.cldProductGallery = cloudinary;" />

As long as this snippet is part of the rendered HTML and is not injected after the page load

@asad-rafter
Copy link
Contributor Author

@yuval-cloudinary the requested changes has been updated

window.renderCloudinaryGalleryWidget();
}
</script>
<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" onload="window.cldProductGallery = cloudinary; window.renderCloudinaryGalleryWidget();"> </script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter this call to window.renderCloudinaryGalleryWidget() is (possibly) executed before we have the div "cld-gallery" in the DOM.
Are we able to inject it after the "

" and "?

If so, then we would be able to remove the additional call to the function after the document is ready:
https://github.com/asad-rafter/cloudinary_sfcc_site_cartridge/blob/9ab65cc0dbeaa7e3ec12e9e4a1fc869096563d6d/cartridges/int_cloudinary/cartridge/js/cloudinaryWidgets.js#L5

Copy link
Contributor Author

@asad-rafter asad-rafter Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuval-cloudinary cld-gallery is already present in DOM, there is no issue with it, everything seems to be working

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter When reviewing the generated HTML on view-source:https://zzgt-007.dx.commercecloud.salesforce.com/s/RefArch/electronics/televisions/flat%20screen/vizio-vp504fM.html?lang=en_US I see that the script tag is written before the div tag.
Please move this line to the lower part of the ISML, remove the second call on the cloudinaryWidgets.js and deploy for testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuval-cloudinary do you want to remove window.renderCloudinaryGalleryWidget(); from script tag?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter I like the window.renderCloudinaryGalleryWidget(); in the script tag, it just needs to be added lower at the rendered HTML

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuval-cloudinary changes have been made and deployed on 007

@@ -53,6 +50,7 @@
<iscomment>Custom start: add cloudinary PGW</iscomment>
<isif condition="${pdict.cloudinary && pdict.cloudinary.isEnabled && (pdict.cloudinary.galleryEnabled || pdict.cloudinary.isGalleryEnabled)}">
<isinclude template="product/components/cloudinaryGallery" />
<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" onload="window.cldProductGallery = cloudinary; window.renderCloudinaryGalleryWidget();"> </script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuval-cloudinary made the changes

@@ -55,6 +52,10 @@
</div>
</div>
<isinclude template="product/components/setItems" />

<isif condition="${dw.system.Site.current.preferences.custom.CLDGalleryEnabled}">
<script src="${dw.system.Site.current.preferences.custom.CLDGalleryJSURL}" onload="window.cldProductGallery = cloudinary; window.renderCloudinarySetGalleryWidgets();"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@yuval-cloudinary yuval-cloudinary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @asad-rafter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants