inline JavaScript issue | Community
Skip to main content
Level 5
September 19, 2021
Solved

inline JavaScript issue

  • September 19, 2021
  • 2 replies
  • 2599 views
Hello Team,
 
AEM version: 6.5.6
In publish instance, all JavaScript code written in slightly html get removed automatically . Anyone having some idea around it.
Eg.
In one of component sightly html:
<script type=...>
var a = "1222";
</script>
 
PROBLEM: 
In author instance, we get this variable with wcmmode=disabled.but in publish code...all code starting from opening script tag, gets removed.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arvind-1

Thanks all for your reply.

 

Root Cause:  Some other project running on same instances have Link Transformer Implementation and one of its feature was to strip off script tag for page content.

 

Ideally, we should do such implementation with Site Path as input parameter so It does not create issues for other sites.

 

Thanks once again.

2 replies

Umesh_Thakur
Community Advisor
Community Advisor
September 20, 2021

are you using dispatcher URL to access the publish instance when you see the issue?

is minification enabled on your publish intance? if yes then try to see with minification disabled.

by the way by default wcmmode is disabled on publisher so chek in this way also.

Hope this will help.

Umesh Thakur

 

arvind-1Author
Level 5
September 20, 2021

Hi Umesh,

 

Thank you for your reply.

 

As I written above, We are using JS code directly in SIGHTLY HTML, not using any client lib.

 

Do you still think, minification might be the issue?

 

I verified again, its not minification issue.

 

Regards,

AP

 

 

arvind-1AuthorAccepted solution
Level 5
September 20, 2021

Thanks all for your reply.

 

Root Cause:  Some other project running on same instances have Link Transformer Implementation and one of its feature was to strip off script tag for page content.

 

Ideally, we should do such implementation with Site Path as input parameter so It does not create issues for other sites.

 

Thanks once again.

Bhuwan_B
Community Advisor
Community Advisor
September 20, 2021

@arvind-1 Please refer to below URL and check if it helps you understand your issue:

 

https://www.netcentric.biz/insights/2015/08/aem-sightly-style-guide.html

 

Avoid inline JavaScript or CSS.

 

In order to encourage keeping a clean separation of concerns, HTL has by design some limitations for inline JavaScript or CSS. First, because HTL doesn't parse JavaScript or CSS, and therefore cannot automatically define the corresponding escaping, all expressions written there must provide an explicit context option. Then, because the HTML grammar ignores elements located inside a <script> or <style> elements, no block statement can be used within them.

 

Therefore, JavaScript and CSS code should instead be placed into corresponding .js and .css files. Data attributes are the easiest way to communicate values to JavaScript, and class names are the best way to trigger specific styles.