Server-Side JavaScript

Marketing Cloud Engagement uses JavaScript code that is processed on our servers. Instead of using the browser to render JavaScript client-side, Server Side JavaScript (SSJS) is executed on Marketing Cloud Engagement servers. Use Core server-side JavaScript functions to personalize landing pages and create applications. Use Platform server-side JavaScript functions to work with messages, landing pages, and applications.

All functions native to JavaScript, such as arrays, math functions, the EVAL function, and try catch blocks work with server-side JavaScript. SSJS doesn't work with the Document Object Model (DOM) or with external libraries.

You can duplicate the functionality of AMPscript using SSJS. However, SSJS can also handle more advanced procedures. For example, SSJS supports arrays and advanced exception handling.

You should exclusively use AMPscript or Platform object server-side JavaScript functions in email messages and reserve your use of Core library server-side JavaScript to landing pages and applications.

From there, several factors can influence your choice to use one language over another:

  • AMPscript can simply and efficiently handle inline personalization or simple IF ELSE statements.
  • AMPscript can better handle use cases where each subscriber needs to see unique content than can server-side JavaScript.
  • AMPscript can present a shorter learning curve than server-side JavaScript for users new to scripting languages in general.

In general, the vast majority of users can handle the tasks they need to perform using AMPscript. Ultimately, many factors help determine which language helps you complete your task in the most elegant and efficient manner possible. However, the above factors can help you make a more informed decision.

Server-side JavaScript interacts with Marketing Cloud Engagement using the Platform class and the Core library. These libraries allow server-side JavaScript to be updated while maintaining previous versions in order to avoid breaking pre-existing code. You can use all commands and syntax outlined in the JavaScript specifications as part of your server-side JavaScript offerings.

SSJS activities time out after 30 minutes. You can prevent timeouts and failures by optimizing your SSJS activities. If your script consistently runs longer than 10 minutes, we recommend using a different tool, such as Data Cloud for Marketing, to transform your data.