Master’s thesis Master’s Programme in Computer Science

Benefits and Challenges of Isomorphism in Single-Page Applications: A Case Study and Review of Gray Literature

Aleksi Huotala

May 18, 2021

Faculty of Science University of Helsinki Supervisor(s) Dr. M. Luukkainen, Prof. T. Mikkonen Examiner(s) Dr. M. Luukkainen, Prof. T. Mikkonen

Contact information

P. O. Box 68 (Pietari Kalmin katu 5) 00014 University of Helsinki, Finland

Email address: [email protected].fi URL: http://www.cs.helsinki.fi/ HELSINGIN YLIOPISTO – HELSINGFORS UNIVERSITET – UNIVERSITY OF HELSINKI Tiedekunta — Fakultet — Faculty Koulutusohjelma — Utbildningsprogram — Study programme

Faculty of Science Master’s Programme in Computer Science

Tekijä — Författare — Author

Aleksi Huotala

Työn nimi — Arbetets titel — Title Benefits and Challenges of Isomorphism in Single-Page Applications: A Case Study and Review of Gray Literature Ohjaajat — Handledare — Supervisors

Dr. M. Luukkainen, Prof. T. Mikkonen

Työn laji — Arbetets art — Level Aika — Datum — Month and year Sivumäärä — Sidoantal — Number of pages

Master’s thesis May 18, 2021 42 pages

Tiivistelmä — Referat — Abstract

Isomorfiset web-sovellukset yhdistävät staattisten Hypertext Markup Language (HTML) - sivujen ja Single-page application (SPA) -sovellusten parhaat puolet. Isomorfinen web-sovellus jakaa koodia palvelimen ja käyttöliittymän välillä.

Isomorfisista web-sovelluksista ei ole tehty kovinkaan paljoa tieteellistä tutkimusta. Web- sovellusten suorituskyvyn, käyttökokemuksen ja kehittäjäkokemuksen parantaminen on suosittu tietojenkäsittelytieteen tutkimusaihe. Tässä tutkielmassa tutkitaan isomorfismin hyötyjä ja haasteita SPA-sovelluksissa.

Isomorfismin hyötyjen ja haasteiden tutkimiseksi suoritettiin kirjallisuuskatsaus ja tapaus- tutkimus. Kirjallisuuskatsauksessa käytettiin lähteenä internetistä löytyviä artikkeleita, joita etsittiin neljältä eri verkkosivustolta. Kirjallisuuskatsausta varten kerättyihin artikkeleihin suoritettiin laaduntarkastus, jotta niitä voitaisiin käyttää osana tieteellistä tutkimusta. Tapaus- tutkimus suoritettiin kehittäjähaastatteluna, jossa haastateltiin isomorfisia web-sovelluksia tun- tevia kehittäjiä. Sekä kirjallisuuskatsauksen että tapaustutkimuksen tuloksia vertailtiin, ja niistä muodostettiin yhteenveto.

Kirjallisuuskatsauksen ja tapaustutkimuksen tuloksena isomorfismi SPA-sovelluksissa tuo etuja sekä käyttäjille että kehittäjille. Isomorfismi SPA-sovelluksissa on haastavaa toteuttaa. Iso- morfismilla on myös muita, lähinnä kehittäjiä koskevia haittoja. Isomorfismi parantaa sovelluk- sen suorituskykyä ja hakukonekyvykkyyttä. Isomorfismin käyttö mahdollistaa ohjelmakoodin jakamisen palvelimen ja käyttöliittymän välillä, mutta se lisää sovelluksen monimutkaisuutta. Sovelluskirjastojen tuki on yksi isomorfismin ongelmista, joka kehittäjien tulee huomioida. Tämän tutkimuksen tulokset antavat kehittäjille syitä ja motivaatiota kehittää isomorfisia web- sovelluksia ja siirtää olemassa olevia sovelluksia käyttämään isomorfismia.

ACM Computing Classification System (CCS) Information systems → World Wide Web → Web applications

Avainsanat — Nyckelord — Keywords isomorphism,,server,web

Säilytyspaikka — Förvaringsställe — Where deposited Helsinki University Library

Muita tietoja — övriga uppgifter — Additional information Software study track HELSINGIN YLIOPISTO – HELSINGFORS UNIVERSITET – UNIVERSITY OF HELSINKI Tiedekunta — Fakultet — Faculty Koulutusohjelma — Utbildningsprogram — Study programme

Faculty of Science Master’s Programme in Computer Science

Tekijä — Författare — Author

Aleksi Huotala

Työn nimi — Arbetets titel — Title Benefits and Challenges of Isomorphism in Single-Page Applications: A Case Study and Review of Gray Literature Ohjaajat — Handledare — Supervisors

Dr. M. Luukkainen, Prof. T. Mikkonen

Työn laji — Arbetets art — Level Aika — Datum — Month and year Sivumäärä — Sidoantal — Number of pages

Master’s thesis May 18, 2021 42 pages

Tiivistelmä — Referat — Abstract

Isomorphic web applications combine the best parts of static Hypertext Markup Language (HTML) pages and single-page applications. An isomorphic web application shares code between the server and the client.

However, there is not much existing research on isomorphic web applications. Improving the performance, user experience and development experience of web applications are popular re- search topics in computer science. This thesis studies the benefits and challenges of isomorphism in single-page applications.

To study the benefits and challenges of isomorphism in single-page applications, a gray literature review and a case study were conducted. The articles used in the gray literature review were searched from four different websites. To make sure the gray literature could be used in this study, a quality assessment process was conducted. The case study was conducted as a developer survey, where developers familiar with isomorphic web applications were interviewed. The results of both studies are then compared and the key findings are compared together.

The results of this study show that isomorphism in single-page applications brings benefits to both the developers and the end-users. Isomorphism in single-page applications is challenging to implement and has some downsides, but they mostly affect developers. The performance and search engine optimization of the application are improved. Implementing isomorphism makes it possible to share code between the server and the client, but it increases the complexity of the application. Framework and library compatibility are issues that must be addressed by the developers. The findings of this thesis give motivation for developers to implement isomorphism when starting a new project or transforming existing single-page applications to use isomorphism.

ACM Computing Classification System (CCS) Information systems → World Wide Web → Web applications

Avainsanat — Nyckelord — Keywords isomorphism,javascript,server,web

Säilytyspaikka — Förvaringsställe — Where deposited Helsinki University Library

Muita tietoja — övriga uppgifter — Additional information Software study track Contents

List of Acronymsi

1 Introduction1

2 Background3 2.1 Isomorphic web application ...... 3 2.2 Single-page application...... 5 2.3 Server-side rendering...... 7 2.4 State management ...... 8 2.5 Search engine optimization...... 9

3 Research Approach 11 3.1 Research Questions...... 11 3.2 Gray Literature Review ...... 11 3.2.1 Search Query ...... 12 3.2.2 Inclusion and Exclusion Criteria...... 12 3.2.3 Extracting Data...... 14 3.3 Case Study ...... 14 3.3.1 Case Description ...... 16 3.3.2 Data Collection and Units of Analysis ...... 16 3.3.3 Data Analysis...... 16

4 Results 19 4.1 Gray Literature Review ...... 19 4.1.1 What are the benefits of isomorphic web applications? ...... 19 4.1.2 What are the challenges of adopting isomorphism in single-page ap- plications?...... 21 4.2 Case Study ...... 25 4.2.1 How the developers got familiar with isomorphic web applications . 25 4.2.2 How much experience the developers have about isomorphic web applications...... 25 4.2.3 How the developers described isomorphic web applications . . . . . 26 4.2.4 Benefits of isomorphic web applications...... 26 4.2.5 Downsides and challenges of isomorphic web applications ...... 27 4.2.6 Surprises of isomorphic web application development ...... 30 4.2.7 Effects of isomorphic web applications for the developers ...... 31 4.2.8 The general feeling about isomorphic web applications ...... 31 4.2.9 Developing isomorphic web applications in another case ...... 32 4.3 Comparison of results...... 32

5 Discussion 35 5.1 How isomorphic web applications affect the end-users? ...... 35 5.2 What does isomorphism bring for developers? ...... 36 5.3 Validity of the results...... 37

6 Conclusions 39

Bibliography 41 List of Acronyms

AJAX Asynchronous JavaScript and XML

API Application Programming Interface

CPU Central Processing Unit

CSS Cascading StyleSheets

DOM

HTML Hypertext Markup Language

HTTP Hypertext Transfer Protocol

JSON JavaScript Object Notation

NPM Node.js Package Manager

REST Representational State Transfer

SPA Single-page application

SSR Server-side rendering

SEO Search engine optimization

TTI Time To Interactive

TTFB Time To First Byte

UI User interface

UX User experience

V8 Google’s open-source high-performance JavaScript and WebAssembly engine

WWW World Wide Web

XHR XMLHttpRequest 1 Introduction

The increased popularity of the World Wide Web (WWW) has lead to the development of software for the web (Taivalsaari et al., 2008). Asynchronous JavaScript and XML () started to gain traction almost 20 years ago, which lead to the introduction of XMLHttp- Request (XHR) Application Programming Interface (API) (Scott, 2015). The XHR API can be used to fetch data asynchronously on the client-side (Scott, 2015). The interest to merge XHR with HTML and JavaScript made web applications evolve from static HTML web pages into complex JavaScript applications. Developers are continuously looking for ways to improve the performance and user experience of their web applications. They also value the developer experience, which they aim to improve by using new software libraries and tools.

The Single-page application (SPA) was introduced in 2002 (Birdeau et al., 2002). A SPA is a JavaScript application, which does not reload the page if the user navigates in it (Mikowski and Powell, 2014). With the release of Angular.js 1 and Backbone.js 2 in 2010, web applications have become more dynamic and can serve more richful content to the end-users. This, however, has introduced some problems regarding site performance and Search engine optimization (SEO) (Silva and Farah, 2018). In some cases, web crawlers fail to index SPAs correctly (Silva and Farah, 2018). SPAs might also be slow to load on mobile devices because the page is rendered with JavaScript code. Older devices, which do not support JavaScript, cannot run JavaScript SPAs. The proposed solution for the performance and SEO-related issues of SPAs is the isomorphic web application architecture (Silva and Farah, 2018). Isomorphic web applications combine the best parts of statically generated websites and SPAs (Gordon, 2018). An isomorphic web application first renders the initial page server- side and sends it to the browser. The browser then attaches event handlers and Document Object Model (DOM) handlers to the initial page markup, which is called hydration (Face- book Inc., 2013). After hydrating the application in the client, the application behaves like a SPA (Silva and Farah, 2018). This all happens in full transparency for the client, where the user browsing the site might not even notice that the application has switched

1https://angularjs.org/ 2https://backbonejs.org/ 2 from a static markup webpage to an interactive JavaScript application. Isomorphic web applications share code between the server and the client (Silva and Farah, 2018). The code that runs in both environments is called Universal JavaScript (Rauschmayer, 2015). Isomorphic web applications provide good performance and user experience for the end user. From the developers’ point of view, the isomorphic web application architecture leads to increased complexity. The isomorphic web application architecture also has a steep learning curve. Software architecture requirements and the lack of proper toolkits for making a web ap- plication that uses the same programming language in both the server and the client are the reasons why these problems haven’t been solved before. JavaScript is nowadays a well-supported programming language across the server and the client, and it is being continuously developed. In this thesis, we studied the benefits and challenges of isomorphism in single-page ap- plications. To study the benefits and challenges, we conducted a gray literature review and a case study that was constructed as a developer survey. The results of the gray literature review are compared to the case study. The results of this joint study are then used to create an overview of the benefits and challenges of isomorphism in single-page applications. The results of the study show that isomorphic web applications improve the performance, user experience, and SEO of single-page applications. The ability to share code between the server and the client improves the maintainability of the application. The complexity of the application increases and code might get duplicated. The framework and library support for isomorphic web applications has a lot of catching up to do. Data fetching and state management are architectural challenges of isomorphic web applications. Isomorphic web applications can be hard to grasp in the beginning, and it might be not worth the trade-off of increased complexity to implement isomorphism in single-page applications. The structure of the study is as follows. First, in Chapter2, we introduce prerequisite information, which is important for the base of this thesis. Next, in Chapter3, we talk about our research approach and introduce the research questions for this study. Chapter 4 presents the results of this study. In Chapter5, we discuss the results of this study. In the last chapter, Chapter6, we conclude the study as a whole. 2 Background

In this chapter, we introduce isomorphic web applications, SPAs, Server-side rendering (SSR), State management, and SEO, which are all important for the base of this thesis.

2.1 Isomorphic web application

An isomorphic web application is a web application that shares the application’s code between the server and the client (NR, 2015). Executing the same code in different environments require polyfills for the environment-specific dependencies. A polyfill is a piece of code that emulates an API, so it can function in a different environment (Sons et al., 2013). Isomorphic web applications combine the best parts of single-page applications and stat- ically generated websites (Gordon, 2018). In Figure 2.1, the isomorphic web application architecture is shown. From Figure 2.1 we see that the application’s state is shared be- tween the server and the client. The code of the application is bundled into a JavaScript file, which will be downloaded by the browser.

The server constructs the initial HTML markup by using the application’s state and User interface (UI) code. The server can also do Hypertext Transfer Protocol (HTTP) requests to external APIs. The data from HTTP responses are then processed and inserted into the initial HTML markup. The application’s state is encoded and injected into the HTML template, which can later be accessed by the client. The final operation the client needs to do is to hydrate the application (Gordon, 2018). Hydration means attaching existing event handlers and DOM handlers to the HTML docu- ment (Facebook Inc., 2013). In this phase, the application’s state generated by the server will be decoded. After hydration has been done, the isomorphic web application functions like any other single-page application (Gordon, 2018). If the hydration fails, the appli- cation might not function correctly; the UI might flicker, output errors in the browser’s developer console or be otherwise completely unusable. 4

Figure 2.1: Isomorphic web application architecture. 5 2.2 Single-page application

A single-page application is a web application that does not reload the page, if the user navigates in it (Mikowski and Powell, 2014). Single-page applications work by embedding the source code of the application into a JavaScript file, which is downloaded by the browser for execution. Single-page applications adopt AJAX to the structure of the entire application (Scott, 2015).

AJAX was introduced in the 1990s to make web applications behave more like desktop applications (Paulson, 2005). AJAX can be used to fetch data without actually reloading the webpage (Paulson, 2005). It makes desktop applications more dynamic and responsive (Paulson, 2005). The single-page application functions as follows:

1) The server responds to the user’s request with the initial HTML page markup, as seen in Figure 2.2. 2) The user’s browser downloads other assets, such as executable JavaScript code and Cascading StyleSheets (CSS) files. 3) After the assets have been downloaded, the JavaScript code is executed. The JavaScript code will mount the application into the initial page markup.

4) After all AJAX requests for fetching data have been completed, the page has finished loading. There are many JavaScript front-end frameworks available, which can be used to develop single-page applications. The most popular front-end frameworks of today are listed in Table 2.1. React.js 3 is an open-source front-end framework developed by Facebook. It was first released in 2013 and is in active development (Facebook Inc., 2013). With over ten million downloads to date (Table 2.1), React.js is currently the most popular JavaScript front-end application of the three. Vue.js 4 and Angular 5 are front-end frameworks that compete with React.js, which both have good developer backing with tens of thousands of stars in GitHub. 3https://reactjs.org 4https://vuejs.org/ 5https://angular.io/ 6

Table 2.1: Comparison of downloads and GitHub stars of front-end frameworks, as of 5th May 2021 (React vs Vue vs Angular 2021).

Downloads (all time) GitHub stars React.js 10,854,762 167,872 Vue.js 2,303,841 182,805 Angular 577,932 59,610

Figure 2.2: Single-page application architecture. 7 2.3 Server-side rendering

Server-side rendering (SSR) is a technique used to render web pages on the server, rather than on the client (Sun, 2019). Single-page applications render the initial page on the client using JavaScript, which requires JavaScript support from the . Backbone.js, React.js, Angular, and Vue.js supports server-side rendering out of the box, meaning that an existing single-page application could be transformed into a server-side rendered application (Mukkamala, 2018; Airbnb, 2012).

When the user makes an HTTP request to the server-side rendered application, the server starts to generate static HTML. For example, server-side rendering of the React.js compo- nent in Listing 2.1 outputs a static HTML representation seen in Listing 2.2. The event handlers and component identifiers, which React.js uses internally are also inserted as element attributes in the HTML elements.

1 // App.js

2 import React from"react";

3

4 const App = () => (

5

6

    7

  • console.log("Clicked first")}>First
  • 8

  • console.log("Clicked second")}>Second
  • 9

10

11 );

12

13 export default App;

Listing 2.1: A React.js component that will be server-side rendered. 8

1 // Server.js

2 import React from"react";

3 import ReactDOMServer from"react-dom/server";

4 import App from"./App";

5

6 ReactDOMServer.renderToString();

7 /*

8

9 class="application"

10 data-reactid=".0"

11 data-react-checksum="-1358679199"

12 >

13

    14

  • First
  • 15

  • Second
  • 16

17