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

ctrl.srcsetbg

v0.0.2

Published

load's background images based on the browserd width via the srcset attribute

Downloads

18

Readme

Intro

I needed simple responsive backgrounds for more than one project and I haven't found a utility that is flexible enough or fit my needs, so I wrote one.

Features

  • AMD support
  • Small foot print: 803 bytes (minified)
  • Simple usage (srcset style)
  • Passes validation
  • Modern Browser support only
  • Does what it does and nothing more

Excluded by design

  • Events (on load and resize): Use your favourite framework, library or vanilla js function or whatever you like for that.
  • Throttling events: I'd suggest something like lodash's _.throttle() but it's up to you.
  • CSS defaults: Use your own CSS as you need it.

Getting started

Clone Repository, download or install via npm install --save-dev srcsetbg

Markup

<div class="srcsetbg"
  data-srcset="img/xs.png 420w, img/s.png 780w, img/m.png 1024w, img/l.png 1400w, img/xl.png 1920w">

Note: the script uses the ℕw param as maximum width with one execption: the largest param is used as minimum width.

JS

Once included the script is included and the markup is ready, just run: ctrlSrcSetBg(); By default the script looks for elements, that contains the class name srcsetbg. Of course you can override the class name like so: ctrlSrcSetBg('my-own-selector');

A little bit more advanced but not that much

The script just uses the data-srcset attribtue to extracts and map the values and set one of them as background image. If you use an event listener for the 'resize' event, you may want to throttle the execution, because events can be expensive.

Example: AMD/jQuery/lodash/Coffeescript:

# require libs/modules
_ = require 'lodash'
$ = require 'jquery'
srcsetbg = require 'ctrl-srcsetbg' # set custom CSS selector

# init event listeners
$(window).on('resize', _.throttle(srcsetbg, 50)) # throttle the resize event
$(window).on('ready', srcsetbg) # this one needs no throttling