In December 2021, I threw together a proof of concept for delegating event handler logic in Optimizely Content Cloud to sandboxed JavaScript, executed server-side.
For this particular POC, I was able to change the URL setting logic from the Edit Mode UI and have that logic used without redeploying any file-based code. Traditionally, this is something that has required custom C#, deployed into the runtime.
I used Jint which is an open-source C# wrapper around ECMAScript.
I stored the JS on a start page property called UrlSegmentBuilder
. This could be edited from the UI (a better IDE would have been helpful).
This particular code set the URL segment of a new page to the current date (ex: 2022-01-05
).
The way I wrote it, you just needed to set the data.Segment
value in the JS. (But, see below, because there are a bunch of other ways to get the data in and out of Jint. I don’t know what the best way would be – this would require some testing and feedback.)
Here is the event handler code I used. Clearly, this would need to be generalized, include error handling, and use some execution constraints for safety.