Skip to content

Instantly share code, notes, and snippets.

@matthewp
Last active May 1, 2019 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewp/4c5d41032627089a1dbb7b170a333860 to your computer and use it in GitHub Desktop.
Save matthewp/4c5d41032627089a1dbb7b170a333860 to your computer and use it in GitHub Desktop.
Client/server abstractions

One of the most difficult problems in web development today is the need to use the same views to render HTML on a web server and to update DOM nodes to reflect changes that occur on the client.

This desire comes down the need to server render for SEO, performance, and fallback reasons, while additionally needing complex, interactive applications.

Most frameworks today have consolidated on the idea of Isomorphic JavaScript, sometimes also called Universal JavaScript, as a solution to this problem.

Problem

I find isomorphism to be an inadequate solution to the use-case stated above. Isomorphism has the following problems:

Leaky abstraction

The abstraction used to enable isomorphism is the component model. In a component model UI is built up self-contained "components", objects that represent what should be rendered and some state.

However this abstraction is client-centric and that fact often leaks. This manifests in problems such as:

  • Memory leaks - Caused by assuming a single-user and a relatively short lifespan of the application. One example of a memory leak would be storing state in an array in some global scope.
  • Security issues - Again caused by single-user assumption, things like a session might be stored in some global state and then accessed by another user's request by mistake.
  • Environment dependent code - Use of code that is not isomorphic but instead depends on one environment's APIs; ie use of window.getComputedStyle(). Since component frameworks are client-centric you often have to work around their use on the server by avoiding running the non-compatible code on the server (or attempt to shim the environment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment