ebay-predict

0.0.6 • Public • Published

ebay-predict Build Status

ebay-predict is a simple tag to prefetch static assets from a prediction service. A prediction service is a server endpoint, that responds with the suggested JSON schema (see below). If the service is not hosted on the same origin as the page, please ensure proper CORS support is enabled. <ebay-predict> triggers the prefetch only after the page load event and use the requestIdleCallback API, to ensure the current page is rendered without any interferance. If requestIdleCallback API is not available, then the provided delay is used.

Usage

  1. Install and save the module
npm install ebay-predict --save
  1. Add dependency in your page browser.json
"ebay-predict/browser.json"
  1. The module exposes a tag <ebay-predict>. This can be embeded in the <footer> tag of page HTML
<html>
...
<footer>
    <ebay-predict src="https://www.ebay.com/sch/predict" delay="200" limit="2"/> 
</footer>
</html>

<ebay-predict> Attributes

Name Type Stateful Description
src String No prediction service endpoint (mandatory)
delay String No Only used when requestIdleCallback API is not available. A delay in milliseconds for the prefetch to trgger, after the page load event (default: "200")
limit String No a limit on the number of resources (for each type) to be prefetched. Use caution when prefetching more than 2 resources, as that may contend with current page bandwidth (default: "2")

Server response

Prediction service JSON schema and sample response

JSON Schema

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "css": {
      "type": "array",
      "items": [
        {
          "type": "string"
        },
        {
          "type": "string"
        }
      ]
    },
    "js": {
      "type": "array",
      "items": [
        {
          "type": "string"
        },
        {
          "type": "string"
        }
      ]
    },
    "media": {
      "type": "array",
      "items": [
        {
          "type": "string"
        },
        {
          "type": "string"
        }
      ]
    }
  }
}

Sample response

{
    "css": ["https://ir.ebaystatic.com/rs/c/br/inception-PMg1-OXo.css", "https://ir.ebaystatic.com/rs/c/br/highlnfe-BTZUdVe3.css"],
    "js": ["https://ir.ebaystatic.com/rs/c/br/inception-dnRHPO-V.js", "https://ir.ebaystatic.com/rs/c/br/highlnfe-AK2d_fr4.js"],
    "media": ["https://i.ebayimg.com/00/s/MzZYNDI=/z/BGEAAOSw8FRZqY4x/$_57.PNG", "https://i.ebayimg.com/images/g/aYoAAOSwl89cAW9D/s-l500.webp"]
}

Browser support

  • Chrome (desktop & Android)
  • Firefox
  • Opera
  • Safari (desktop & iOS)
  • IE8+
  • Android WebKit

Issues

Have a bug or a feature request? Please open a new issue

Maintainers

Contribute

Pull Requests welcome. Please submit Github issues for any feature enhancements, bugs or documentation problems.

License

Copyright (c) 2018 eBay Inc.

Released under the MIT License

Dependents (0)

Package Sidebar

Install

npm i ebay-predict

Weekly Downloads

1

Version

0.0.6

License

MIT

Unpacked Size

12.6 kB

Total Files

14

Last publish

Collaborators

  • senthilp