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

plastic-diff-redirect

v1.0.4

Published

Client side build selection like prpl-server-node, but on client

Downloads

7

Readme

plastic-diff-redirect

Client side build selection for Polymer, like prpl-server-node, but on client

Lllows you to serve different Polymer builds based on the capability of the browser, even on a static server. The function chooses a 'build' from an array of 'builds' in polymer.json which is compatable with the current browser (like prpl-server-node) and redirects the client to that build.

Install

Install with npm or yarn:

npm install --save plastic-diff-redirect
yarn add plastic-diff-redirect

Usage

Folder Structure

Your folder structure will look something like this if you use basePath in each build definition (see polymer.json section below):

/
|--index.html (copy sample-index.html)
|--polymer.json (copy from your polymer project)
|--build (copy in your polymer build folder)
   |--build1
   |--build2
   |--build3

or if you use autoBasePath in the root of polymer.json:

/
|--index.html (copy sample-index.html)
|--polymer.json (copy from your polymer project)
|--build1 (copy all the folders inside your polymer project build folder)
|--build2
|--build3

index.html

Create an index.html file in the root of your project (you can copy sample-index.html):

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
    <title></title>
    <script src="node_modules/ua-parser-js/src/ua-parser.js"></script>
    <script src="node_modules/plastic-diff-redirect/plastic-diff-redirect.js"></script>
</head>
<body>    
</body>
</html>

polymer.json

You will copy the polymer.json file from your project. You may need to use the basePath property for each build if you are using the first folder structure above or if you will be serving from other than the root folder (e.g. https://someone.github.io/my-project-name). If you are not using basePath in each build set autoBasePath to true.

See polymer.json specification for more details.

Example

For a github project page for some-project-name

"builds": [
    {
      "name": "esm-bundled",
      "browserCapabilities": ["es2015","modules"],
      "js": { "minify": true },
      "css": { "minify": true },
      "html": {"minify": true },
      "bundle": true,
      "addServiceWorker": true,
      "basePath": "some-project-name/build/esm-bundled/"
    },
    {
      "name": "es6-bundled",
      "browserCapabilities": ["es2015"],
      "js": {
        "minify": true,
        "transformModulesToAmd": true,
        "compile": "es2015" // new feature, see https://github.com/Polymer/tools/pull/270
      },
      "css": { "minify": true },
      "html": { "minify": true },
      "bundle": true,
      "addServiceWorker": true,
      "basePath": "some-project-name/build/es6-bundled/"
    },
    {
      "name": "es5-bundled",
      "js": {
        "minify": true,
        "compile": true,
        "transformModulesToAmd": true
      },
      "css": { "minify": true },
      "html": { "minify": true },
      "bundle": true,
      "addServiceWorker": true,
      "basePath": "some-project-name/build/es5-bundled/"
    }

Thats It

When the user hits the index.html file they will be redirected to the build folder matching their browser capabilities.

About the Code

The code here is based on tools from the Polymer team:

  • browser-capabilities https://github.com/Polymer/tools/tree/master/packages/browser-capabilities
  • prpl-server-node https://github.com/Polymer/prpl-server-node

The functions used were just modified to run in the browser and downleveled to ES5.

Issues

Problems or questions can be submitted as issue in the github repository. Every effort is made to respond the same day.

Contributions

Contributions via pull request are always welcome and appreciated.

License

MIT