AntiSamy sanitizer cleans some of the HTML tags and styles, how can we solve that?

Issue

  • We turned on AntiSamy but it removes certain HTML code and CSS styles from our Web Content articles.

Environment

  • DXP 7.0+

Resolution

Usage of HTML and CSS in Web Content article HTML fields

Web content articles are not really intended to be used like this - they should not replace proper web development standards and processes. So while you are not prevented from adding JavaScript or CSS, but we do not recommend doing so.

Using CSS this way in your web content articles is not really the best option.

  • the same code may be added to the page multiple times, inflating the size of the served pages, resulting in larger load times for users
  • the order of execution may depend on the order in which the web content articles are displayed
  • such code may also be hard to maintain: imagine what happens if anyone wants to change the overall styles of the pages, while there are lots of articles with specific CSS contained in them; users would probably go through all the articles, and manually correct them, which is not only time-consuming but also prone to manual errors

Our Recommendation

We recommend creating and hosting one or more JavaScript / CSS files, then embedding them when needed.

  • On 7.0, the best way to do that is creating a theme.
  • On 7.4, we have features like JavaScript Client Extensions and CSS Client Extension
  • You can also host your files somewhere on your server or in the Documents and Media, and load them on a page using the JavaScript or CSS fields of the pages

Additional Information

Este artigo foi útil?
Utilizadores que acharam útil: 1 de 1