Serialization
Qwik is resumable. Resumable means that the server can serialize the state of the application as well as the state of the framework into HTML. The browser can then deserialize the state and continue (resume) where the server left over. Serialization is the process of taking the object graph in a heap (memory) and turning it into strings that can be written into HTML.
JSON
The simplest way to think about serialization is through JSON.stringify
. However, JSON has several limitations. Qwik can overcome some limitations, but some can't be overcome, and they place limitations on what the developer can do. Understanding these limitations is important when building Qwik applications.
Limitations of JSON which Qwik solves:
- JSON produces DAG. DAG stands for directed acyclic graph, which means that the object which is being serialized can't have circular references. This is a big limitation because the application state is often circular. Qwik ensures that when the graph of objects gets serialized, the circular references get properly saved and then restored.
- JSON can't serialize some object types. For example, DOM references, Dates, etc... Qwik serialization format ensures that such objects can correctly be serialized and restored. Here is a list of types that can be serialized with Qwik:
- DOM references
- Dates (not yet implemented)
- Function closures (if wrapped in QRL).
Limitations of JSON that Qwik does not solve:
- Serialization of classes (
instanceof
and prototype) - Serialization of
Promise
s, Streams, etc...