What is a client-side app and why should I care?
June 02, 2012, 3 min read
For years, we have been developing websites and applications that run on the server, using the language of our choice (Python, PHP, Ruby, etc). The server took care of all the hard work in order to respond to users’ requests.
A typical workflow of a server-side app is:
- User requests http://example.com/page
- Server (let’s say Apache) identifies /page as the requested resource and delegates the task of handling the request to a back-end language; PHP for example.
- PHP loads its config files, makes all the necessary queries to the database (e.g. MySQL), loads and parses templates, constructs the page’s HTML code and populates it with data from the database.
- In the meantime, the server keeps track of the user’s session and credentials, the application’s state and more.
So why is this wrong? It’s not, but it can be better.
In the aforementioned example, the server takes all the burden of handling every single user request. That leaves the user waiting between each request for the server to render a whole new page and respond.
Think for example, a page where you have a list of products that you want to sort in a specific order (by price, by popularity, etc). Every time you choose a sorting option, your browser needs to make a server request and wait for the whole page to be rendered from scratch. Various techniques like server-side caching help to speed up this process, but still is not efficient.
When Ajax was introduced some years ago, it enabled the creation of more dynamic and interactive web apps. Users didn’t have to wait for whole pages to reload when interacting with partial aspects of them. Extending on the product page example, most websites now allow you to sort products without waiting for a full-page refresh. Instead, your browser sends the sorting request to the server, which responds with a list of products, in the order that you asked for, that replaces the current product view in your browser. This is more efficient, as the amount of data that travel back and forth between the client and the server is reduced to the absolute minimum. All while you can continue interacting with the website with no interruptions.
Now, that looks way more efficient, but even with Ajax, there are many redundant and repetitive tasks. We still need the server to manage URLs, load and parse templates, construct the HTML code, populate it with data, keep track of the user’s session, credentials and do all sorts of related housekeeping. Furthermore, if we want to develop a mobile app, our server-side code is practically useless and we have to code everything from scratch for each mobile platform (Android, iOS, etc).