Expand my Community achievements bar.

SOLVED

inline JavaScript issue

Avatar

Level 6
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.
1 Accepted Solution

Avatar

Correct answer by
Level 6

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.

View solution in original post

4 Replies

Avatar

Community Advisor

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

 

Avatar

Level 6

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

 

 

Avatar

Correct answer by
Level 6

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.

Avatar

Community Advisor

@arvind 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.