npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

third-party-capital

v3.0.0

Published

<img alt="Third Party Capital Logo" title="Third Party Capital Logo" src="https://user-images.githubusercontent.com/12476932/229881508-f9ef68db-8ee7-4795-8de8-80a50145bbd0.png" width="150">

Downloads

2,323,222

Readme

Third Party Capital

Third Party Capital is a resource that consolidates best practices for loading popular third-parties in a single place.

The project provides implementations that can be used in the following languages:

Rationale

There is a large, cross-functional Chrome initiative that aims to improve third-party resource loading on the web. One part of this effort is to provide a default set of recommendations, or "components," to developers. These components will help developers sequence and fetch popular third-party resources at the right time to minimize their overall impact to page performance.

Instead of duplicating these recommendations in multiple places and expecting maintainers for each tool to keep them up to date, Third Party Capital consolidates them in a single repository with an API. This API makes it possible for consumers to import the recommendations directly within their tooling.

Here's a demo of a @next/third-parties package that shows how Next.js can import recommendations from Third Party Capital and re-export them as framework components at build-time.

Schema

Third Party Capital is an experimental library and its specification is subject to change.

The loading recommendation for each third-party resource is defined with the following JSON schema:

{
  id: string;
  description: string;
  website?: string;
  html?: {
    element: string;
    attributes: {
      [string]?: string,
      src?: {
        url: string;
        slugParam: string;
        params: Array<string>;  
      }
    };
  };
  stylesheets?: Array<string>;
  scripts?: Array<{
    key?: string;
    url: string | {
      url: string;
    };
    params: Array<string> ;
    optionalParams?: Record<string, string | number | undefined | null>;
    strategy: "server" | "client" | "idle" | "worker";
    location: "head" | "body";
    action: "append" | "prepend";
  } | {
    key?: string;
    code: string;
    params: Array<string> ;
    optionalParams?: Record<string, string | number | undefined | null>;
    strategy: "server" | "client" | "idle" | "worker";
    location: "head" | "body";
    action: "append" | "prepend";
  }>;
}

These properties provide a heuristic for consumers to decide how, when, and where to load a particular third-party to minimize its impact on performance. Here are the details:

  • id (required): Identifier string
  • description (required): Short description of third-party entity
  • website (optional): URL address of website
  • html (optional*): HTML element to be inserted where 3PC component is placed. The attributes property allows you to include a list of any default attributes and their values which will be overwritten if the user specifies a different value. The src attribute is the only property that needs to follow a specific structure:
    • url: The URL of the resource
    • slugParam: The name of the parameter that is used the user to either include or replace the slug of the URL
    • params: An array of parameter names that when used as arguments by the user are assigned as query parameters to the URL
  • stylesheets (optional*): URLs of any stylesheets that need to be loaded
  • scripts (optional*): Object array of external and inline scripts (code blocks) with the following properties:
    • url: The URL of the script (only used for external scripts)
    • code: String literal of the script to inject (only used for inline scripts)
    • key (optional*): Key string
    • params: An array of parameter names that when used as arguments by the user are assigned as query parameters to the URL
    • optionalParams: An object, where keys are optional parameters and values are default values.
    • strategy: String literal to denote loading strategy of third-party script (on the server, on the client, during browser idle time, or in a web worker)
    • location: String literal to denote whether to inject the script in or (only useful if strategy=server is used)
    • action: String literal to denote whether to prepend or append the script (only useful if strategy=server is used)

* A value must be included for at least one of the main attributes (content, stylesheets, or scripts)

Supported Third Parties

Third Party Capital is an experimental library and the list of supported third parties is subject to change.

The third-party resources that are currently provided in Third Party Capital, along with their suggested loading practices, are:

  • Google Analytics: Off-load to a web worker
  • Google Maps (Embed): Use the loading attribute to lazy load the embed
  • YouTube Embed: Use lite-youtube-embed

Although the details are still being finalized, only a select number of third-parties that meet certain usage criteria will be included. Please do not submit any requests to include new third-parties.

Limitations

Third Party Capital would be able to provide loading details for many third-parties, but some scenarios cannot be supported with the current schema:

  • Third-parties that need to load early and block page rendering as a result (e.g. cookie consent forms, A/B testing providers)
  • Third-parties that require developers to run code after certain user interactions (e.g. using reCAPTCHA and storing the final score for each request)
  • Third-parties that require users to select between many different choices (e.g. selecting a particular font from Google Fonts)