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

yass

v0.2.1

Published

Yet Another SrcSet implementation

Downloads

6

Readme

yass.js

Yet Another SrcSet implementation.

How to use it

Add yass.js just after the last img tag on your page. Yass works from a mobile-first perspective, so the properties are seen as a minimal value. So 500w should be visible on a 500px or wider screen.

The order of the queries is not important, these are sorted by Yass. To force the update of the (including new) images, just call YASS() in your code.

Simple img tag with srcset

This may cause 2 requests for a image, when it matches one in the srcset.

<img src="small.png"
  data-srcset="medium.png 500w, [email protected] 2x, large.png 1000w, [email protected] 1000w 2x">

Img tag with noscript fallback

Now only the image that matches the device/viewport is loaded, and non-js users (also spiders) will get the fallback between the noscript tags. With a library like Modernizr you can hide the images for non-js users.

<img data-srcset="small.png, medium.png 500w, [email protected] 2x, large.png 1000w, [email protected] 1000w 2x">
<noscript><img src="medium.png"></noscript>
.no-js img[data-srcset] { display: none; }

API

YASS([obj], [options], [callback]) One method with multiple functions. When called without arguments it updates all current instances of Yass, and searches and updates new images. The return value will be all YassSrcSet instances.

You can pass an object that will be updated. This must be a valid DOM object. You can pass options (see below), and a callback which is called each time the src will be changed. The return value will be the created instance.

Options

You can set these properties for all instances, by setting these on window.YASS_OPTIONS before including yass.js.

ready_class: 'yass-ready'

ClassName to be set on the element when it has been Yassified

src_attr: 'src'

Property to set. This can be anything, most times src, but can also be poster etc..

srcset_attr: 'srcset'

Property to read the candidates from

CSS trick

For slightly better user experience you can add some css to hide the images with a srcset onload. Yass gives the img the class yass-ready when loaded. So with a simple line of css you can hide the srcset images:

img[data-srcset] { visibility: hidden; }
img.yass-ready { visibility: visible; }

Check the /demo directory for a sample implementation.

Notes

Yass.js is small, under 500bytes when minified and gzipped...

Tested in Chrome 28, Android 4.2, IOS6, BlackBerry10 and IE6. Should work on most/all browsers.