@resolute/rio
v0.1.0
Published
Responsive Image Optimizer
Downloads
2
Maintainers
Readme
Locally
- Source may be a URL or a local file
- If a URL, perform HEAD request and parse
etag
header. Generate the source hash as{xxHash64(URL)}-{etag}
. - If a local file, read contents of file and generate source hash as
{xxHash64(file contents)}
. - Note: we must create a lock to prevent re-reading or re-requesting the same resource over and over. This would act as an ephemeral cache of the source hash. We must figure out how to purge this cache during periods of long execution contexts—like a “watch” scenario.
- If a URL, perform HEAD request and parse
- Generate an
{optionsHash}
by normalizing the options (mime type, width, height).- Options must be normalized so that swapping the order of width and height does not generate a different hash.
- If
{sourceHash}-{optionsHash}
exists in local FS cache, return it.
- GET rio-gcf passing the
{sourceHash}
and the options, ~~and optionally a locally existingIf-None-Match: "{variantHash}"
~~ —doesn’t make sense: if we’re caching locally, then we do not need to check with the server. If the response is:- 404
- The rio-gcf server does not have the source.
- Proceed to upload POST source where the request body is either 1) the file contents or the 2) URL.
- Note: we must also create a lock for source uploading to prevent overloading rio-gcf with may upload request.
- 200
- The rio-gcf server has the source and is either 1) generating the variant based on the options, or 2) found the asset in its GCS cache and is returning that.
- ~~304~~
- ~~The rio-gcf server has the source, and the ETAG (
{variantHash}
) passed inIf-None-Match
request header is the correct fresh version.~~
- ~~The rio-gcf server has the source, and the ETAG (
- 404
Server-side
GET Request Headers
- ~~
If-None-Match: "{variantHash}"
~~ Accept: {mime type}
Request URL Search ParamssourceHash
width
(optional)height
(optional)
- Generate an
{optionsHash}
by normalizing the options (mime type, width, height). - …
Possible States
- Variant locally on filesystem by
{sourceHash}-{optionsHash}
- exists
- does not exist
- Source in GCS
- exists
- does not exist
- Variant in GCS
- exists
- does not exist
If the Variant ({sourceHash}-{optionsHash}
) exists locally, simply return it along with its meta ({sourceHash}-{optionsHash}.meta
).
If the Source does not exist in GCS, upload (POST) it to GCF/GCS.