Skip to main content

 –

Best practices for using custom JavaScript

Suggest edit Updated on December 1, 2021
Applicable to Theme Cosmos applications

By following best practices for using custom JavaScript, you ensure that you can fully benefit from such functionalities as custom error messages or client-side validation.

The following list includes guidelines that can help you ensure that custom JS runs as intended:

  • Test third-party script before deployment to avoid potential conflicts with internal script.
  • Verify that the browsers that you specify can display the customized code, because Pega Platform does not validate custom HTML code.
  • Pay attention to the order in which you put the scripts in the code, because the system runs the scripts sequentially.
  • Store the JavaScript code in its own separate JS file, because inline JavaScript inserted into a custom section or control requires more maintenance. Separate files also minify the JavaScript source code and enable JavaScript validation and linting.
  • For the highest quality and security, reduce the use of HTML fragment rules in application rulesets.
  • Attach global scripts to a top-level harness, or include them as part of a static bundle.
  • Load a local script for a particular custom section by using the <pega:onlyonce> directive.
  • If you use your custom control in multiple sections, load the JavaScript file during the initial loading of the portal by attaching it to the portal harness.
  • If the custom control is used infrequently, load the JavaScript file at the end of stream processing by using the <pega:static> JSP tag.
Did you find this content helpful? YesNo

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Ready to crush complexity?

Experience the benefits of Pega Community when you log in.

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us