Abstract
Static
fromFetch the resource a given link
points to, and return it as a Resource.
This method does not modify the given link; the caller can store the created Resource in
link.resource
, to grow a tree of links and resources.
link.resource = await Resource.fromLink(link)
The newly created Resource.
The link pointing to the resource.
Optional environment configuration.
Static
fromCreate a Resource from a Blob and a URL, and a subresource type.
Note that the URL is not resolved (see fromLink for that), but is used to interpret any relative links that the resource may contain.
Currently, the subresourceType
is mandatory, and determines what subclass of Resource is
instantiated (in freeze-dry, this method is only used for subresources, so the expected type
is always known). The Blob’s MIME type is ignored.
An instance of a subclass of Resource matching the given subresource type.
Optional
subresourceOptional
config?: GlobalConfigStatic
getDetermine the Resource subclass to use for the given subresource type.
The appropriate Resource subclass, or undefined
if the type is not
supported.
The type of subresource expected by the parent resource, e.g.
'image'
or 'style'
. Note this is not the same as its MIME type.
Perform a function on each subresource link.
A promise that completes when all invocations have completed.
Invoked on each subresource link.
Readonly
Abstract
urlURL of the resource.
Readonly
Abstract
blobA Blob with the current resource content.
Readonly
Abstract
linksAn array of Links, providing a live view on the links defined in the resource. Changing the target of a link will change the resource content.
An array of Links (a subset of links), containing only subresource links, and
for whose subresourceType
a Resource subclass exists. That is, those links that fromLink accepts.
Resource is an abstraction to help deal with links and subresources of web pages.
Each Resource has content and a URL, and may have links to other URLs, which can again be represented as a Resource, and so on; resources can thus form a tree of (sub)resources.
For example, a web page (DomResource) might link to a stylesheet (StylesheetResource) which may link to a font (LeafResource).
Each such subclass of Resource exposes the links it contains. Note that besides the user-visible links made by
<a>
elements, links are also created by e.g. thesrc="…"
of an<img>
element (in HTML), or theurl(…)
in abackground-image
value (in CSS).The target of a Link can be modified, which updates the resource content accordingly.
Each subclass also provides a
dry()
method that transforms the contents to be usable outside of its original context (e.g. served from a different URL), and to be as accurately as possible a snapshot of its current state (e.g. dynamic DOM state is made part of its HTML).Any Resource’s content can be accessed as a blob. Subclasses may also provide other formats:
DomResource.doc
,DomResource.string
, andStylesheetResource.string
.