What are the differences between server-side and client-side programming?

  • I've seen questions (mainly on Stack Overflow), which lack this basic knowledge. The point of this question is to provide good information for those seeking it, and those referencing to it.

    In the context of web programming, what are the differences between Server-side programming and Client-side programming? Which languages belong to which, and when do you use each of them?

    Server-side programming is writing code that runs on the server, using languages supported by the server (such as Java, PHP, C#; it is possible to write code that executes on the server-side in JavaScript). Client-side programming is writing code that will run on the client, and is done in languages that can be executed by the browser, such as JavaScript.

    I think you should include in the question that you refer only to web programming, as in the current form the answers are not complete. For example, server-client communication need not be done in HTTP; client side might not use a browser, etc.

    @KSteff you are welcome to edit my question to add that.

    When the web was young it was good practice to put most of your logic heavy lifting on the server side (java/c++) and keep browser logic intentionally thin - particularly since browsers back then were not ready for prime time. Now this emphasis has reversed such that browser based tools (Angular.js) are where the bulk of the web application heavy lifting logic now resides (away from the increasingly stripped down server side logic). This has been facilitated by modern industrial strength browsers running extremely fast javascript engines (within an order of magnitude of native code).

    @ScottStensland - That statement is very inaccurate. How would you save data to the server for example, without server side logic? Security and Permissions? Connecting to protocol based API's ? Data Validation ?

  • Background

    Web development is all about communication. In this case, communication between two (2) parties, over the HTTP protocol:

    • The Server - This party is responsible for serving pages.
    • The Client - This party requests pages from the Server, and displays them to the user. In most cases, the client is a web browser.
      • The User - The user uses the Client in order to surf the web, fill in forms, watch videos online, etc.

    Each side's programming, refers to code which runs at the specific machine, the server's or the client's.

    Basic Example

    1. The User opens his web browser (the Client).
    2. The User browses to http://google.com.
    3. The Client (on the behalf of the User), sends a request to http://google.com (the Server), for their home page.
    4. The Server then acknowledges the request, and replies the client with some meta-data (called headers), followed by the page's source.
    5. The Client then receives the page's source, and renders it into a human viewable website.
    6. The User types Stack Overflow into the search bar, and presses Enter
    7. The Client submits that data to the Server.
    8. The Server processes that data, and replies with a page matching the search results.
    9. The Client, once again, renders that page for the User to view.


    Server-side Programming

    Server-side programming, is the general name for the kinds of programs which are run on the Server.


    • Process user input.
    • Compiles pages.
    • Structure web applications.
    • Interact with permanent storage (SQL, files).

    Example Languages

    • PHP
    • Python
    • ASP.Net in C#, C++, or Visual Basic.
    • Nearly any language (C++, C#, Java). These were not designed specifically for the task, but are now often used for application-level web services.

    Client-side programming

    Much like the server-side, Client-side programming is the name for all of the programs which are run on the Client.


    • Make interactive webpages.
    • Make stuff happen dynamically on the web page.
    • Interact with temporary storage, and local storage (Cookies, localStorage).
    • Send requests to the server, and retrieve data from it.
    • Provide a remote service for client-side applications, such as software registration, content delivery, or remote multi-player gaming.

    Example languages

    • JavaScript (primarily)
    • HTML*
    • CSS*
    • Any language running on a client device that interacts with a remote service is a client-side language.

    *HTML and CSS aren't really "programming languages" per-se. They are markup syntax by which the Client renders the page for the User.

    +1 for a good answer *with* examples of the uses! Just to nitpick: HTML and CSS are not actually programming languages, so they probably shouldn't be compared to "PHP, ASP, and Nearly any language (C++, C#, Java)". ActionScript might be another good example of a client-side language.

    You fail to identify *why* the server is a server and the client is a client. The server is known about by the client, but not the other way around. The server is expected to be executing at all times, there are no client expectations.

    I would add the fact that a server environment is more controlled. You have no idea what the client is. Also there are security concerns(for both parties) when doing things client side.

    So add it, feel free.

    I disagree with @ChrisMcCall's definition to a point. There could be exceptions to that rule, such as where a server might rely on a client to process data or provide a service to the server for the server to complete a task. Clients also are sharing an increasing amount of the load for scalability and performance such as in SPAs. These technologies blur that definition. A better definition could be that the end-user and the client are synonymous. It is expected that the end-user exists at the client device, whereas all other nodes would be considered server-side.

    You could also say that **Client-side** code works even when you download the page and take it to a computer without internet access, while a **Server-side** code would never work in that scenario (unless you run a local server yourself).

    It depends. Some client-side code depends on the existence of a server (prime example: AJAX).

    Your point under **Uses** "Interact with permanent storage (SQL, files)". SQL is a programming language, not a permanent storage. At most you can interact with databases through SQL. It would have been simpler if you had said just "databases".

    Also, your examples of client-side languages are very reduced. Sticking always with the trio has become a little bit annoying. Moreover, saying that HTML isn't as primary (and nowadays CSS) as Javascript is completely unrealistic. Actually I would say that HTML is absolutely the first language of the web, and it's like that since the early nineties.

    @MadaraUchiha - Not everyone has editing priviledges (to make those changes in your post) - and still many prefer pointing out the change and letting you implement it, so the style is consistent.

    An addition to clientside programming: Next to JavaScript there is WebAssembly now which is supported by all major browsers. It allows writing client side code in C++, Rust, C#...

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM