Add page plugin for Facebook | Community
Skip to main content
Level 4
Aug 16, 2022 7:15 AM UTC
Solved

Add page plugin for Facebook

I'm using AEM as a Cloud Service. I am creating a component which will be used to show the facebook feed of a page. The problem is that I have to add this piece of code: 

<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v14.0"></script>

I can simply add this in the component's html but it is not a standard method to use script tag inside html. For script we can write code in the ui.frontend module. So, let me know how can I add this using a standard method.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Aug 16, 2022 4:35 PM UTC

I wanted to know according to the standards of AEM. Like if the script is required to be added in ui.frontend or directly in the component's html file.


You are adding the external javascript reference which can be directly added in the component html

<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v14.0">

If you have to write your own javascript and CSS then use ui.frontend module. 

Arun Patidar

8 replies

Mohit_KBansal
Employee
Aug 16, 2022 9:42 AM UTC

@nikita24tailor You can add custom Html/scripts in your components. Though it's advised to include such scripts in the head/footer section (based on the recommendation by the script provided), so you should consider overlaying the page component's customheaderlibs.html/customfooterlibs.html file to include this script.

Translate
arunpatidar
New Participant
Aug 16, 2022 1:26 PM UTC

I would not recommend to add script in head section until it is really necessary. 

 

Adding javascript in head section can block page rendering. That is why javascript are mostly added to footer/last section of the page body.

Translate
Arun Patidar
Mohit_KBansal
Employee
Aug 16, 2022 1:37 PM UTC

@arunpatidar Thanks for pointing, I mean the same, though some scripts need to be explicitly added in the head based on recommendation (eg. jquery, launch)

Translate
arunpatidar
New Participant
Aug 16, 2022 7:18 AM UTC

Hi,

There is no problem with writing javascript inside body 

You can do it as component.

Translate
Arun Patidar
Level 4
Aug 16, 2022 9:36 AM UTC

Can we add script tag in component's html?

Translate
arunpatidar
New Participant
Aug 16, 2022 1:24 PM UTC

Yes, you can do that

https://www.w3schools.com/js/js_whereto.asp 

Translate
Arun Patidar