Rich-text Reply

Single page app challenges

SpeekApp 04-22-14

Single page app challenges

[ Edited ]

I have not seen much around optimizely running in a single page app with screens that are not even loaded at runtime.

For quite awhile it severely limited our ability to use optimizely. However after a late night recently I found a rather elegant solution.

First some background. Our app ( has a series of views which comprise a 'page' which are all dynamically loaded and constructed on demand.

Our solution was to broadcast an event to Optimizely's version of jQuery that contained a reference to the view we were constructing. We broadcast a onBeforeRender event and an onAfterRender event. Each event contains a reference to the class itself. With these interception points in place we are now able to use basic jQuery (in optimizely) to adjust markup and even entire behaviors on a view level without any runtime concerns.

This has opened up a world of possibilities for us and hasn't come at any real cost, just a few lines in a base class.

What's also nice is we no longer have to be concerned with targeting, we simply tie it to view construction universally.

Level 1

tobyurff 04-22-14

Re: Single page app challenges

Thanks for sharing! It's an interesting approach and there are many more ways of accommodating such dynamic applications. I'm describing one common way here (, just in case you're interested. This is one of the simplest ways of integrating Optimizely if you have one central method that handles state / view changes.
Aicke 06-10-14

Re: Single page app challenges

Everyone who wants to use that approach, the generic term is

There are several implementations of this, some simple ready-to-use ones are: (or

@tobyurff your link is kinda wrong, the ")," is included by mistake
Everything is hard, before it is easy.
Level 2