Skip to main content
LinkedIn
Copied!

Table of Contents

Best practices for using custom JavaScript

Version:

Only available versions of this content are shown in the dropdown

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?

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 Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us