How to do server-side testing for single page app optimization

Reading Time: 5 minutes

Gettin’ technical.

We talk a lot about marketing strategy on this blog. But today, we are getting technical.

In this post, I team up with WiderFunnel front-end developer, Thomas Davis, to cover the basics of server-side testing from a web development perspective.

The alternative to server-side testing is client-side testing, which has arguably been the dominant testing method for many marketing teams, due to ease and speed.

But modern web applications are becoming more dynamic and technically complex. And testing within these applications is becoming more technically complex.

Server-side testing is a solution to this increased complexity. It also allows you to test much deeper. Rather than being limited to testing images or buttons on your website, you can test algorithms, architectures, and re-brands.

Simply put: If you want to test on an application, you should consider server-side testing.

Let’s dig in!

Note: Server-side testing is a tactic that is linked to single page applications (SPAs). Throughout this post, I will refer to web pages and web content within the context of a SPA. Applications such as Facebook, Airbnb, Slack, BBC, CodeAcademy, eBay, and Instagram are SPAs.

Defining server-side and client-side rendering

In web development terms, “server-side” refers to “occurring on the server side of a client-server system.”

The client refers to the browser, and client-side rendering occurs when:

  1. A user requests a web page,
  2. The server finds the page and sends it to the user’s browser,
  3. The page is rendered on the user’s browser, and any scripts run during or after the page is displayed.
Static app server
A basic representation of server-client communication.

The server is where the web page and other content live. With server-side rendering, the requested web page is sent to the user’s browser in final form:

  1. A user requests a web page,
  2. The server interprets the script in the page, and creates or changes the page content to suit the situation
  3. The page is sent to the user in final form and then cannot be changed using server-side scripting.

To talk about server-side rendering, we also have to talk a little bit about JavaScript. JavaScript is a scripting language that adds functionality to web pages, such as a drop-down menu or an image carousel.

Traditionally, JavaScript has been executed on the client side, within the user’s browser. However, with the emergence of Node.js, JavaScript can be run on the server side. All JavaScript executing on the server is running through Node.js.

*Node.js is an open-source, cross-platform JavaScript runtime environment, used to execute JavaScript code server-side. It uses the Chrome V8 JavaScript engine.

In laymen’s (ish) terms:

When you visit a SPA web application, the content you are seeing is either being rendered in your browser (client-side), or on the server (server-side).

If the content is rendered client-side, JavaScript builds the application HTML content within the browser, and requests any missing data from the server to fill in the blanks.

Basically, the page is incomplete upon arrival, and is completed within the browser.

If the content is being rendered server-side, your browser receives the application HTML, pre-built by the server. It doesn’t have to fill in any blanks.

Why do SPAs use server-side rendering?

There are benefits to both client-side rendering and server-side rendering, but render performance and page load time are two huge pro’s for the server side.

(A 1 second delay in page load time can result in a 7% reduction in conversions, according to Kissmetrics.)

Server-side rendering also enables search engine crawlers to find web content, improving SEO; and social crawlers (like the crawlers used by Facebook) do not evaluate JavaScript, making server-side rendering beneficial for social searching.

With client-side rendering, the user’s browser must download all of the application JavaScript, and wait for a response from the server with all of the application data. Then, it has to build the application, and finally, show the complete HTML content to the user.

All of which to say, with a complex application, client-side rendering can lead to sloooow initial load times. And, because client-side rendering relies on each individual user’s browser, the developer only has so much control over load time.

Which explains why some developers are choosing to render their SPAs on the server side.

But, server-side rendering can disrupt your testing efforts, if you are using a framework like Angular or React.js. (And the majority of SPAs use these frameworks).

The disruption occurs because the version of your application that exists on the server becomes out of sync with the changes being made by your test scripts on the browser.

NOTE: If your web application uses Angular, React, or a similar framework, you may have already run into client-side testing obstacles. For more on how to overcome these obstacles, and successfully test on AngularJS apps, read this blog post.

Testing on the server side vs. the client side

Client-side testing involves making changes (the variation) within the browser by injecting Javascript after the original page has already loaded.

The original page loads, the content is hidden, the necessary elements are changed in the background, and the ‘new’ version is shown to the user post-change. (Because the page is hidden while these changes are being made, the user is none-the-wiser.)

As I mentioned earlier, the advantages of client-side testing are ease and speed. With a client-side testing tool, a marketer can set up and execute a simple test using a WYSIWYG editor without involving a developer.

But for complex applications, client-side testing may not be the best option: Layering more JavaScript on top of an already-bulky application means even slower load time, and an even more cumbersome user experience.

A Quick Hack

There is a workaround if you are determined to do client-side testing on a SPA application. Web developers can take advantage of features like Optimizely’s conditional activation mode to make sure that testing scripts are only executed when the application reaches a desired state.

However, this can be difficult as developers will have to take many variables into account, like location changes performed by the $routeProvider, or triggering interaction based goals.

To avoid flicker, you may need to hide content until the front-end application has initialized in the browser, voiding the performance benefits of using server-side rendering in the first place.

WiderFunnel - client side testing activation mode
Activation Mode waits until the framework has loaded before executing your test.

When you do server-side testing, there are no modifications being made at the browser level. Rather, the parameters of the experiment variation (‘User 1 sees Variation A’) are determined at the server route level, and hooked straight into the javascript application through a service provider.

Here is an example where we are testing a pricing change:

“Ok, so, if I want to do server-side testing, do I have to involve my web development team?”


But, this means that testing gets folded into your development team’s work flow. And, it means that it will be easier to integrate winning variations into your code base in the end.

If yours is a SPA, server-side testing may be the better choice, despite the work involved. Not only does server-side testing embed testing into your development workflow, it also broadens the scope of what you can actually test.

Rather than being limited to testing page elements, you can begin testing core components of your application’s usability like search algorithms and pricing changes.

A server-side test example!

For web developers who want to do server-side testing on a SPA, Tom has put together a basic example using Optimizely SDK. This example is an illustration, and is not functional.

In it, we are running a simple experiment that changes the color of a button. The example is built using Angular Universal and express JS. A global service provider is being used to fetch the user variation from the Optimizely SDK.

Here, we have simply hard-coded the user ID. However, Optimizely requires that each user have a unique ID. Therefore, you may want to use the user ID that already exists in your database, or store a cookie through express’ Cookie middleware.

Are you currently doing server-side testing?

Or, are you client-side testing on a SPA application? What challenges (if any) have you faced? How have you handled them? Do you have any specific questions? Let us know in the comments!

Enjoy this post? Share with your friends and colleagues:



Thomas Davis

Full Stack Web Developer

Thomas rocks the WiderFunnel Dev team using his grit, innovative thinking and a strong passion for code to solve problems.

  • Octavi Miró

    Hi Natasha and Thomas, great article, congrats!

    As a member of a CRO team I can relate a lot to this article and the challenges of A/B testing in SPAs. I also thought it would be great to share one of our experiences and get your point of view of the workaround we are planning to implement. We are not sure if it is a common or best practice, so getting your feedback would be great.

    The situation is the same as described in this article. We have a SPA developed under Angular.js and we are having so much trouble to load the new variation as expected (rendering and timing issues).

    The suggested workaround is about developing the new variation in server-side under a new url and create a redirect test between the original SPA and the new version (this configuration would be done within our current A/B testing tool). Thus, we would be able to:

    – load the test faster and as expected
    – implement the test idea through the standard development work flow
    – facilitate the release of the new variation if it ends up being the winner
    – take advantage of the targeting (audiences), bucketing and reporting features from our A/B testing tool

    For example if our SPA control is we would implement a new variation/branch of the SPA under

    Once implemented and released, we would setup a new test in our current A/B testing tool that would redirect half of the traffic going to to

    Is this a common or best practice for server side implementation with an A/B testing tool?

    I hope I made it clear,


    • Thomas Davis

      Thank you for sharing your experience, Octavi! I can definitely see your workaround as a viable solution.

      For best practices, this really depends on the technologies you have implemented, as there is no universal authority on testing tool implementation best practices on the server. However, I think that when building out the testing tool functionality, the principle of separation of concerns can come in handy.

      One issue I can see with your approach is that rendering different routes for each variations may tightly couple your application to the testing tool. If you’re using a MVC framework on the server, like Laravel or Rails, you would have to build out a new route for every experiment variation you create, with their own controllers to render the correct views.

      I would suggest looking at before action callbacks, for example Rail’s before_action, (most MVC’s have some kind of equivalent). This would allow you to extract the testing tool logic to it’s own module – you could figure out which variation the user is in and render the corresponding template or inject a global variable into your angular app (building the Angular app out with the variation changes on initialization) Also, this would remove any targeting issue related to having different urls for each variation, as all variations would share the same url.

      I hope this helps, and please let me know if you need to follow up on anything here!

      Best of Luck,


  • Cross Channel Marketing

    Fantastic Technical Post.

  • jai .P

    hi ,
    Thanks for article..
    I am looking for help on SPA testing using API request/response.

    We have 1 section as SPA in mobile app ,I am using Apache Jmeter for testing the app using API request/response.
    Steps – I am login to app using login api & it succeeds.
    But the problem is with SPA ,on this page I send API request to server & response get javascript ,Jmeter does not execute the javascript (Its not browser).
    Thus can not not test this module.
    This is blocker for me.
    Please advice