Client-Server Interactions |
Today we are living in fiercely competitive environment on outsourcing horizon and we need to create products with high quality with least investment of time and resources. All quality software products need standard coding with the best programming practices. If anything goes wrong in code, it may lead to frequent debugging. In other words, it proves waste of time and resources behind non-productive work.
However, best programming skills come with prolonged experiences and thorough understanding of technologies, tools, and techniques. At Lujayn, the team leaders of our hire dedicated programmers departments frequently do complains regarding to the lack of proper understanding of programming in junior web developers. Therefore, they always avoid their participation at critical levels and let them to learn things correctly and in righteous manners.
Among such complains I have sort out one that is surfacing frequently in discussions. Let me translate that in words. It is lack of understanding of differences between client side programming and server side programming. Thus, they tend to mix up the server side code in to client side code and vice verso. This convoluted code trigger unexpected results and some tough to detect bugs in the products at the end of the project. Let me explain this in details.
Understanding of Server-side and Client-side Programming
Understanding Client-Server Terms
When we use the website or web application or a web app on mobiles, we have two parties working behind the display of web interface on your devices. The first one is your device itself and another is web server that communicate with your devices using HTTP protocol or other modern ways/protocols we can say cloud-computing technologies. Let’s stick to the HTTP protocol for ease in understanding.Technically, server is a single entity, which is located at remote and central place and communicating with the innumerable devices across the world using Internet. Its prime role is to server the web pages or web interfaces of web applications. These web pages or web interfaces are displaying on the various devices with browsers.
These browser enabled devices term as clients, the clients of the server, which are using the services of the server. No doubt, in a broad concept, not all the client devices need browsers to use services and HTTP to communicate, modern web services in particular. For sake of simplicity, we avoid all exceptions and stick with HTTP and browser concepts.
Now, we know about client and server terms with their respective roles. Let’s check what happens at the code level during the client-server communication. At first place, client wants to see the web page in browser to meet its needs on the web. In due course, client sending request for a particular website by typing URL in browser using HTTP protocol.
Processes on the Server
This request is reaching to the server and server begins processing on it. It find out the source code of the requested website in its databases/storage/memory. Server Runs the source code and create an output in form of HTML or other standard forms, which can render on the browsers of the client devices across the world.In next step, server send the website code to the client device and now client device/its browser, turns it into the human visible web pages on the screen of device. When device render the code sent by server it processes on it
Server-side Scripts
In above scenario, we have seen that server runs the source code on its machines using its own mechanisms/compilers. During this process on server, some code turns into the different forms in output files or omitted from the inclusion in to the output. Therefore, they term as server-side code or programming and PHP, ASP.NET, C++, C#, Java, ROR, Perl, etc. are claiming as server-side scripts/languages in web development industries.This server-side scripts do following actions on server and triggers outputs accordingly.
- Its first and foremost function is to process the user inputs
- Create pages for clients to display
- Structure or frame the web application
- interact with databases
Processes on the Client
Once user start using client devices, she put some input to process and create a request to send to the respective server. When server in return send the outputs to the client, its process on its and interpret the code and render it in browsers or interfaces, which are human readable. The performance of client depends on that what the code is coming back to the client from the server and what the capacities of the client devices to process it. Due to known constraints of mobile devices, responsive designers and programmers prefer to have more processes on the server, while in case of big sister devices web programmers go leeway.Client-side Scripts
As we know that server is mainly sending markups and styles in return of the requests made by clients. Therefore, HTML and CSS are main forms of code need to be rendered on the client or browsers. However, server also send JavaScript in some responses along with HTML and CSS. Today other scripts mainly based on JS libraries like jQuery, Media Query, etc. are in use for dynamic and interactive website or web applications for multiple screens.No doubt, the king is still JavaScript and it always renders on the client devices therefore, it creates great confusions for the newbie developers when they embed the JS code in HTML along with other PHP code. In next part, we will see some practical problems and try to understand the differences between server-side and client-side programming paradigm.