Best practices for using custom JavaScript
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.
Previous topic Custom JavaScript in application design Next topic Customizing harnesses globally with JavaScript