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

ajax-component

v0.2.1

Published

A Custom Element that AJAXs its content.

Downloads

3

Readme

ajax-component

ajax-component on NPM Standard JavaScript Style

A Custom Element that AJAXs its content, style, and scripts.

Features

  • HTTP2 first. A component performs AJAX requests to fetch its HTML, CSS, and JS.
  • Scoped CSS. Via the Shadow DOM, ajax-component has native CSS scoping (no build step required).
  • Scoped JavaScript. Execute anything, with access to the global scope, but without polluting it.
  • Familiar. Same old HTML, CSS, and JS. Just new elements.

Install

$ npm i ajax-component --save

Use

Decide on a name for your element (it must contain a -).

HTML

Using your name, add the new element to your markup:

<!-- note that a closing tag is required -->
<ajax-component></ajax-component>

Then, add the these attributes to load your resources:

| Attribute | Extension | Required | Optional | | :-------- | :-------: | :------: | :------: | | content | .html | | ✓ | | style | .css | | ✓ | | script | .js | | ✓ |

<!-- will load HTML only -->
<!-- while not technically required, scoped CSS and/or JS isn't useful without HTML -->
<ajax-component content="path/to/file.html"></ajax-component>

<!-- will load HTML content, scoped CSS, and scoped JS -->
<ajax-component
  content="path/to/file.html"
  style="path/to/file.css"
  script="path/to/file.js">
</ajax-component>

Finally, add the fetch attribute to your element.

It must have an initial value of false (or this wouldn't be an AJAX component).

<ajax-component
  fetch="false"
  content="path/to/file.html"
  style="path/to/file.css"
  script="path/to/file.js">
</ajax-component>

JavaScript

Using your name, in your JavaScript, pass it to the import:

// import the default export
// this is a function that accepts an element name
import createAJAXComponent from 'ajax-component'

// call the imported function
// pass the element name as used in the HTML to create the Custom Element
createAJAXComponent('ajax-component')

An element will AJAX its resources when the fetch attribute changes to true.

// selected the element we want to load
const customEl = document.querySelector('ajax-component')

// set the fetch attribute to true
customEl.setAttribute('fetch', 'true')

Browser Support

pjax-component makes use of the Custom Elements v1 API. As such, it runs natively in the following (see caniuse):

  • Chrome 54+
  • Safari 10.1+
  • Opera 42+

Roadmap

  • [ ] Explore polyfill options (potential impact on scoping)

License

MIT. © 2017 Michael Cavalea