Consider a document, say HTML, which has embedded code, say Javascript, which runs to generate parts of the document. Unlike Javascript in a typical webpage these days which can do things like have an event loop responding to input events or make further network calls, the embedded code can do neither of those. It runs once and is done, generating a static content. It is not an active document.
A straightforward application is a document with a text decompression engine built into it. A document could have many sections (perhaps hierarchical) and sections might only get uncompressed on demand, or the browser could uncompress the whole thing all at once; it should make no difference.
Code could produce more code, which could be executed only when the user reads that section.
Slightly problematic is finite code can easily produce an infinitely long document. If so, don't try to print the whole thing. This feature could be useful for a teaching document to be able to produce unlimited random examples illustrating something.
While not strictly necessary, we prohibit the embedded code from making further network calls. The document, with its embedded code, is entirely entirely self-contained once downloaded. Once all the embedded code has run to completion (modulo infinite documents), the reader can be sure of having the whole thing in front of them. This is a mental model of a document that is familiar to humans, like a finite book. In contrast, web page with active and possibly networked content makes it impossible for a user to "have" or be sure to have read or experienced the whole thing.
(Large documents which are only fetched over the network on demand in portions are of course useful for devices with a small footprint, but not the subject of this post.)
Define a subset of Javascript limited to this functionality. Design a way to detect that pages only use such functionality, or a way for pages to declare that they only use such functionality.
No comments :
Post a Comment