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

request-control-js

v3.3.0

Published

Fight back against the rising tide of http requests.

Downloads

54

Readme

Bower version NPM version

Throttle aggressive 3rd party http requests.

$ bower install request-control
$ npm install request-control-js

As viewability becomes the gold standard in advertising metrics, many vendors are hungry for related data. Unfortunately, some programatic and remnant creatives can end up plaguing your site with a relentless flow of http requests - especially from video ads.

Request Control provides you a throttle to take back control of your site performance and enforce a speed limit on http requests per second.

Will this interfere with other site content? Definitely not. Throttling does not engage for the top window context by default - this means only your site's iframes will be affected. There is also a (configurable) grace period of 100 requests before the throttle will kick in, meaning your standard site content will be unaffected.

Won't this interfere with revenue from video remnants? Nope! Since this is only a throttle, video metrics will still be reported from video ads - just at a more sane rate. Once the throttle kicks in, only 1 out of every N (configurable) requests per second will be made.

Request Control is intended to throttle malicious reporting - which may make upwards of 10 http requests per second! At roughly 100KB per request this can add up to some very expensive site visits for your mobile customers.

Using the Throttle

To load Request Control on your site, simply include the built script from dist/reqctrl.min.js and then start the throttle when you're ready to enforce a request speed limit. Request Control will automatically reapply the throttle when possible in any iframes for you.

You can install the JS global object with bower install request-control.

<script src="path/to/reqctrl.min.js"></script>
<script>
    RequestControl();
</script>

Request Control is also provided as a CommonJS module with npm install request-control-js.

var Throttle = require('request-control-js');
Throttle();

Configuration

To better tune the throttle for your site, there are a few options you can customize.

// Default values are as follows:
RequestControl({
    throttle: 100,
    grace: 800,
    top: false,
    log: false
});
  • throttle {Number} Time in milliseconds to wait between successive http requests. Falsy (0 false null undefined) to run the system but disable the throttle and allow all requests to complete.
  • grace {Number} Number of requests to allow before engaging the throttle.
  • top {Boolean} True to throttle the top window as well as iFrames.
  • log {Boolean} True to enable logging. RequestControl logs with Lumberjack to 4 channels: image, ajax, append, gate.

Debugging your Site

Request Control features logging and DOM element highlighting to help you find those problem areas on your site. Just open the JavaScript console in your browser and set the rcDebug variable in the top window.

// Enable DOM node highlighting and enable logging on the fly.
rcDebug = true;

// Print a detailed report of network activity.
// Available reports are: image, ajax, append. You can request reports for
// any of these.
RequestControl.log.report('image ajax'); // Report only image and ajax data.
RequestControl.log.report('append'); // Get append data only.
RequestControl.log.report(); // Get summary only.

// Bind callbacks to log events.
RequestControl.log.on('gate', function (data) {
    if (data.blocked) {
        // Report metrics on blocked content.
    }
});

Stopping the Throttle

After the throttle has been started, you can turn it off with the callable that is returned when you first started the system.

// Start the throttle.
var halt = RequestControl();

// Some time later, stop the throttle.
halt();

  • See: http://cobbdb.github.io/request-control
  • See: http://github.com/cobbdb/request-control
  • License: MIT