Catalog npm
PACKAGE EXPLORERView in registry

@0x1eef/postman

npm

Delivers the assets of a web page asynchronously

Versions collected7
Direct dependencies6From release 0.4.0
Last observed20 Oct, 22:33 UTC

README

Current package documentation

About

Postman is a lightweight library that can download the assets of a web page asynchronously. A classic use-case might be a progress bar that is updated as assets are downloaded.

Example

Postman

Deliver

The "deliver" method initiates the download of a parcel that includes fonts, stylesheets and scripts. Each time an item is downloaded, the progress event is dispatched. When all items have been downloaded, the parcel is ready to be inserted into the DOM. Typically document.fonts is used to append fonts, document.head is used to append styles, and document.body is used to append scripts:

import { Postman, item } from "postman";

const items = [
  item.font("Roboto Regular", "/fonts/roboto-regular.ttf"),
  item.css("/css/main.css"),
  item.script("/js/main.js")
]

const postman = Postman(...items)
postman.addEventListener("progress", (event) => {
  const { progress, parcel } = event.detail
  console.info("progress", progress)
  if (progress === 100) {
    parcel.fonts.forEach((font) => document.fonts.add(font))
    parcel.css.forEach((style) => document.head.appendChild(style))
    parcel.scripts.forEach((script) => document.body.appendChild(script))
  }
})
postman.deliver()

Error

An "error" event is dispatched when an item fails to download, and that includes any item that was fetched with a response code other than 200. The dispatched event provides access to an instance of AbortController that can be used to cancel the download of the remaining items, otherwise the download will continue:

import { Postman, item } from "postman";

const items = [
  item.font("Roboto Regular", "/fonts/roboto-regular.ttf"),
  item.css("/css/main.css"),
  item.script("/js/main.js")
]

const postman = Postman(...items)
postman.addEventListener("error", (event) => {
  const { controller } = event.detail
  controller.abort()
  console.error("error encountered, download cancelled")
})
postman.deliver()

See also

Sources

License

BSD Zero Clause
See LICENSE

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 7

Collected releases
VersionPublishedDirect dependenciesOpen version
0.4.0Registry latest17 May 20256
0.3.016 May 20256
0.2.329 Mar 20256
0.2.229 Mar 20256
0.2.129 Mar 20256
0.2.029 Mar 20256
0.1.029 Mar 20256

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
0x1eef/postman

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:33 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:b549a9230df1ebdf08e55c56541e768697a2f011ed586b1b01394700ac5bf067