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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@traffic-opt/core

v0.1.7

Published

Core utilities for traffic optimization packages.

Readme

@traffic-opt/core

Browser-side iframe loader for creating real, eager iframes from a small init({ sites }) API.

The package is designed for cases where the embedded page should produce normal browser requests and referral signals. It does not guarantee Similarweb, UV, or any third-party analytics outcome, because those systems depend on browser policy, target-site headers, cookies, anti-abuse systems, and the target site's own analytics tags.

Install

pnpm add @traffic-opt/core

Basic Usage

import { init } from "@traffic-opt/core";

const controller = init({
  sites: ["https://example.com/"],
  iframeStyle: {
    width: "100%",
    height: 600,
    opacity: 1,
    border: 0
  }
});

await controller.resize();
controller.destroy();

API

init({
  sites: [
    "https://a.com/",
    { url: "https://b.com/", title: "Site B" }
  ],
  container: "#traffic-opt",
  iframeClassName: "traffic-opt-frame",
  iframeStyle: {
    width: "100%",
    height: 600,
    opacity: 1,
    border: 0
  },
  minHeight: 600,
  referrerPolicy: "no-referrer",
  resizer: true
});
  • sites: Required. URL strings or { url, title } objects.
  • container: A CSS selector or HTMLElement. If omitted, the loader creates a div and appends it to document.body.
  • iframeClassName: Optional class name for created iframes.
  • iframeStyle: Inline iframe-only styles for width, height, minHeight, maxHeight, opacity, and border. Numeric size values may be 0 or greater and are treated as px. opacity may be any value from 0 to 1.
  • minHeight: Default iframe minimum height. Defaults to 600px; numbers may be 0 or greater and are treated as px.
  • referrerPolicy: Defaults to no-referrer.
  • resizer: Enabled by default through @open-iframe-resizer/core. Pass false to disable it or pass an object to forward resizer settings.

By default, created iframes use the real src, loading="eager", no sandbox, and no hidden layout such as display:none or hidden positioning. The default size is visible and non-zero, with normal browser opacity, but you may explicitly configure zero width, height, minHeight, maxHeight, or opacity when you need to test browser request behavior. The library does not inject global CSS.

The loader does not bypass X-Frame-Options or CSP frame-ancestors. If a target site blocks iframe embedding, this package cannot solve that from the browser.

React

import { useEffect, useRef } from "react";
import { init } from "@traffic-opt/core";

import type { TrafficOptController } from "@traffic-opt/core";

export default function App() {
  const containerRef = useRef<HTMLDivElement | null>(null);

  useEffect(() => {
    if (containerRef.current === null) {
      return undefined;
    }

    const controller: TrafficOptController = init({
      sites: [{ url: "https://example.com/", title: "Example" }],
      container: containerRef.current,
      iframeStyle: {
        width: "100%",
        height: 600,
        opacity: 1,
        border: 0
      },
      resizer: false
    });

    return () => {
      controller.destroy();
    };
  }, []);

  return <div ref={containerRef} />;
}

Vue

<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
import { init } from "@traffic-opt/core";

import type { TrafficOptController } from "@traffic-opt/core";

const containerRef = ref<HTMLElement | null>(null);
let controller: TrafficOptController | undefined;

onMounted(() => {
  if (containerRef.value === null) {
    return;
  }

  controller = init({
    sites: [{ url: "https://example.com/", title: "Example" }],
    container: containerRef.value,
    iframeStyle: {
      width: "100%",
      height: 600,
      opacity: 1,
      border: 0
    },
    resizer: false
  });
});

onBeforeUnmount(() => {
  controller?.destroy();
});
</script>

<template>
  <div ref="containerRef" />
</template>

Plain HTML

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>TrafficOpt HTML Example</title>
  </head>
  <body>
    <div id="traffic-opt-example"></div>

    <script src="https://cdn.jsdelivr.net/npm/@traffic-opt/[email protected]/dist/index.global.js"></script>
    <script>
      TrafficOpt.init({
        sites: [{ url: "https://example.com/", title: "Example" }],
        container: "#traffic-opt-example",
        iframeStyle: {
          width: "100%",
          height: 600,
          opacity: 1,
          border: 0
        },
        resizer: false
      });
    </script>
  </body>
</html>