Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-inject

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-inject - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1

docs/fetch-inject-serviceworker-caching.png

6

dist/fetch-inject.es.js

@@ -1,4 +0,4 @@

/*! Fetch Inject v1.7.0 | (c) 2017 Josh Habdas | @license ISC */
/*! Fetch Inject v1.7.1 | (c) 2017 Josh Habdas | @license ISC */
/**
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -23,3 +23,3 @@ * Permission to use, copy, modify, and/or distribute this software for any

*
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -26,0 +26,0 @@ * Permission to use, copy, modify, and/or distribute this software for any

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.7.0 | (c) 2017 Josh Habdas | @license ISC */
/*! Fetch Inject v1.7.1 | (c) 2017 Josh Habdas | @license ISC */
const head=function(e,t,n,o,r,c,i){c=t.createElement(n),i=t.getElementsByTagName(n)[0],c.appendChild(t.createTextNode(o.text)),c.onload=r(o),i?i.parentNode.insertBefore(c,i):t.head.appendChild(c)},fetchInject=function(e,t){if(!e||!Array.isArray(e))return Promise.reject(new Error("`inputs` must be an array"));if(t&&!(t instanceof Promise))return Promise.reject(new Error("`promise` must be a promise"));const n=[],o=t?[].concat(t):[],r=[];return e.forEach(e=>o.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{n.push({text:e[0],blob:e[1]})})))),Promise.all(o).then(()=>{n.forEach(e=>{r.push({then:t=>{e.blob.type.includes("text/css")?head(window,document,"style",e,t):head(window,document,"script",e,t)}})});return Promise.all(r)})};export default fetchInject;

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.7.0 | (c) 2017 Josh Habdas | @license ISC */
/*! Fetch Inject v1.7.1 | (c) 2017 Josh Habdas | @license ISC */
var fetchInject = (function () {

@@ -6,3 +6,3 @@ 'use strict';

/**
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -27,3 +27,3 @@ * Permission to use, copy, modify, and/or distribute this software for any

*
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -30,0 +30,0 @@ * Permission to use, copy, modify, and/or distribute this software for any

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.7.0 | (c) 2017 Josh Habdas | @license ISC */
/*! Fetch Inject v1.7.1 | (c) 2017 Josh Habdas | @license ISC */
var fetchInject=function(){"use strict";const e=function(e,t,n,r,o,i,c){i=t.createElement(n),c=t.getElementsByTagName(n)[0],i.appendChild(t.createTextNode(r.text)),i.onload=o(r),c?c.parentNode.insertBefore(i,c):t.head.appendChild(i)};return function(t,n){if(!t||!Array.isArray(t))return Promise.reject(new Error("`inputs` must be an array"));if(n&&!(n instanceof Promise))return Promise.reject(new Error("`promise` must be a promise"));const r=[],o=n?[].concat(n):[],i=[];return t.forEach(e=>o.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{r.push({text:e[0],blob:e[1]})})))),Promise.all(o).then(()=>{r.forEach(t=>{i.push({then:n=>{t.blob.type.includes("text/css")?e(window,document,"style",t,n):e(window,document,"script",t,n)}})});return Promise.all(i)})}}();

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.7.0 | (c) 2017 Josh Habdas | @license ISC */
/*! Fetch Inject v1.7.1 | (c) 2017 Josh Habdas | @license ISC */
(function (global, factory) {

@@ -9,3 +9,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :

/**
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -30,3 +30,3 @@ * Permission to use, copy, modify, and/or distribute this software for any

*
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -33,0 +33,0 @@ * Permission to use, copy, modify, and/or distribute this software for any

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.7.0 | (c) 2017 Josh Habdas | @license ISC */
/*! Fetch Inject v1.7.1 | (c) 2017 Josh Habdas | @license ISC */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.fetchInject=t()}(this,function(){"use strict";const e=function(e,t,n,o,r,i,c){i=t.createElement(n),c=t.getElementsByTagName(n)[0],i.appendChild(t.createTextNode(o.text)),i.onload=r(o),c?c.parentNode.insertBefore(i,c):t.head.appendChild(i)};return function(t,n){if(!t||!Array.isArray(t))return Promise.reject(new Error("`inputs` must be an array"));if(n&&!(n instanceof Promise))return Promise.reject(new Error("`promise` must be a promise"));const o=[],r=n?[].concat(n):[],i=[];return t.forEach(e=>r.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{o.push({text:e[0],blob:e[1]})})))),Promise.all(r).then(()=>{o.forEach(t=>{i.push({then:n=>{t.blob.type.includes("text/css")?e(window,document,"style",t,n):e(window,document,"script",t,n)}})});return Promise.all(i)})}});
{
"name": "fetch-inject",
"version": "1.7.0",
"version": "1.7.1",
"description": "Dynamically inline assets into the DOM using Fetch Injection.",

@@ -20,9 +20,3 @@ "author": "Josh Habdas <josh@habd.as> (https://habd.as/)",

"scripts": {
"build": "npm-run-all --parallel build:*",
"build:iife": "MINIFIER=off FORMAT=iife rollup -c",
"build:iife.min": "MINIFIER=on FORMAT=iife rollup -c",
"build:es": "MINIFIER=off FORMAT=es rollup -c",
"build:es.min": "MINIFIER=on FORMAT=es rollup -c",
"build:umd": "MINIFIER=off FORMAT=umd rollup -c",
"build:umd.min": "MINIFIER=on FORMAT=umd rollup -c",
"build": "rollup -c",
"clean": "rimraf dist",

@@ -38,5 +32,4 @@ "commit": "git-cz",

"husky": "^0.13.4",
"npm-run-all": "^4.0.2",
"rimraf": "^2.6.1",
"rollup": "^0.41.6",
"rollup": "^0.42.0",
"rollup-plugin-license": "^0.4.0",

@@ -43,0 +36,0 @@ "rollup-plugin-uglify": "^2.0.1",

@@ -11,4 +11,4 @@ <h1 align="center">Fetch Inject</h1>

</a>
<a href="https://cdn.jsdelivr.net/fetch-inject/latest/fetch-inject.min.js">
<img src="http://img.badgesize.io/https://cdn.jsdelivr.net/fetch-inject/latest/fetch-inject.min.js?compression=gzip&style=flat-square" alt="Compressed size of IIFE bundle">
<a href="https://cdn.jsdelivr.net/npm/fetch-inject">
<img src="http://img.badgesize.io/https://cdn.jsdelivr.net/npm/fetch-inject?compression=gzip&style=flat-square" alt="Compressed size of UMD bundle">
</a>

@@ -26,4 +26,2 @@ <a href="https://travis-ci.org/jhabdas/fetch-inject">

<p align="center"><strong><a href="https://news.ycombinator.com/item?id=14380191">Discuss it on Hacker News</a></strong></p>
## Background

@@ -39,46 +37,8 @@

Here are some example waterfalls using Fetch Inject, as well as links to more info and a live demo.
Here's an example waterfall using Fetch Inject to loading the WordPress Twenty Seventeen theme over 4G with an unprimed browser cache.
Loading Bootstrap 4:
[![Fetch Inject Unprimed Cache](https://github.com/jhabdas/fetch-inject/blob/master/docs/fetch-inject-unprimed-cache.png?raw=true)](https://wordcamp.habd.as/)
![Bootstrap 4](https://cloud.githubusercontent.com/assets/440298/24649786/c474c626-195a-11e7-8af8-b0ba0bcc0a71.png "Loading Bootstrap 4 asynchronously in parallel")
Click the image for a live demo of the application used to produce the above waterfall.
Loading jQuery, Transit, Hover Intent, Superfish, Animo and main JS:
![security7.net](https://cloud.githubusercontent.com/assets/440298/25044861/aa97bd7c-215b-11e7-9885-eea39c79c5a5.png "Loading jQuery, Transit, Hover Intent, Superfish, Animo and main JS asynchronously in parallel")
Loading and initializing PhotoSwipe:
![PhotoSwipe](https://cloud.githubusercontent.com/assets/440298/24689725/13984c50-19fb-11e7-9bbe-384e98d558f9.png "Loading and initializing PhotoSwipe")
For a more complex example see article titled [Putting WordPress into Hyperdrive](https://hackernoon.com/putting-wordpress-into-hyperdrive-4705450dffc2) on Hacker Noon. A **live demo** is available on [wordcamp.habd.as](http://wordcamp.habd.as/).
## WordPress Plugin
Fetch Inject has been built into a WordPress plugin, enabling Fetch Injection to work within WordPress. [Initial testing](https://hackernoon.com/putting-wordpress-into-hyperdrive-4705450dffc2) shows Fetch Injection enables WordPress to load pages **300% faster** than conventional methods.
[![Hyperdrive WordPress Plugin logo](https://github.com/wp-id/hyperdrive/blob/master/logo.png)](https://github.com/wp-id/hyperdrive)
Access the plugin beta [Hyperdrive repo](https://github.com/wp-id/hyperdrive) on GitHub and see the related [Hacker Noon article](https://hackernoon.com/putting-wordpress-into-hyperdrive-4705450dffc2) for more details.
## Playground
Try [Fetch Inject on CodePen](https://codepen.io/jhabdas/pen/MpVeOE?editors=0012) using the latest version available on CDN.
Reference the [Use Cases](#use-cases) to get a feel for what it can do.
## Installing
Fetch Inject is available on NPM, Bower and CDN. It ships in the following flavors: IIFE, UMD and ES6.
- Get it on NPM with `npm i -p fetch-inject`
- Bower with `bower i -p fetch-inject`
- CDN [using jsDelivr](http://www.jsdelivr.com/projects/fetch-inject)
To download the lastest minified UMD bundle from the command line:
curl -L -o fetch-inject.umd.min.js https://go.habd.as/fetch-inject-umd-min
See the [Development](#development) section for asset pipelines requiring vanilla AMD and CJS modules.
## Syntax

@@ -109,2 +69,22 @@

## Playground
Try [Fetch Inject on CodePen](https://codepen.io/jhabdas/pen/MpVeOE?editors=0012) using the latest version available on CDN.
Reference the [Use Cases](#use-cases) to get a feel for what it can do.
## Download
Fetch Inject is available on NPM, Bower and CDN. It ships in the following flavors: IIFE, UMD and ES6.
- Get it on NPM with `npm i -p fetch-inject`
- Bower with `bower i -p fetch-inject`
- CDN [with jsDelivr](https://cdn.jsdelivr.net/npm/fetch-inject@1.7.0/dist/)
To grab the latest UMD bundle from CDN:
curl -o fetch-inject.umd.min.js https://cdn.jsdelivr.net/npm/fetch-inject
See the [Development](#development) section for asset pipelines requiring vanilla AMD or CJS modules.
## Use Cases

@@ -307,3 +287,3 @@

If you need vanilla AMD or CJS modules, update the NPM scripts in the package manifest and `npm run build`.
If you need vanilla AMD or CJS modules, update `activeConfigs` in `rollup.config.js`.

@@ -326,4 +306,12 @@ ## Contributing

## WordPress Plugin
Fetch Inject has been built into a WordPress plugin, enabling Fetch Injection to work within WordPress. [Initial testing](https://hackernoon.com/putting-wordpress-into-hyperdrive-4705450dffc2) shows Fetch Injection enables WordPress to load pages **300% faster** than conventional methods.
[![Hyperdrive WordPress Plugin logo](https://github.com/wp-id/hyperdrive/blob/master/logo.png)](https://github.com/wp-id/hyperdrive)
Access the plugin beta [Hyperdrive repo](https://github.com/wp-id/hyperdrive) on GitHub and see the related [Hacker Noon article](https://hackernoon.com/putting-wordpress-into-hyperdrive-4705450dffc2) for more details.
## License
[![ISC](https://img.shields.io/github/license/jhabdas/fetch-inject.svg?style=flat-square)](https://choosealicense.com/licenses/isc/ "ISC License")
[![ISC](https://img.shields.io/github/license/jhabdas/fetch-inject.svg?style=flat-square)](https://github.com/jhabdas/fetch-inject/blob/master/LICENSE "ISC License")

@@ -5,28 +5,34 @@ import uglify from 'rollup-plugin-uglify'

const minifier = process.env.MINIFIER
const format = process.env.FORMAT
const defaultConfig = {
entry: 'src/fetch-inject.js',
plugins: [license({ banner: `/*! Fetch Inject v<%= pkg.version %> | (c) <%= moment().format('YYYY') %> Josh Habdas | @license ISC */` })]
}
const config = {
entry: 'src/fetch-inject.js',
format: `${format}`,
const activeConfigs = [{
format: 'iife',
moduleName: 'fetchInject',
sourceMap: false,
plugins: [
license({
banner: `/*! Fetch Inject v<%= pkg.version %> | (c) <%= moment().format('YYYY') %> Josh Habdas | @license ISC */`
dest: 'dist/fetch-inject.js'
}, {
format: 'es',
dest: 'dist/fetch-inject.es.js'
}, {
format: 'umd',
moduleName: 'fetchInject',
dest: 'dist/fetch-inject.umd.js'
}]
activeConfigs.forEach(activeConfig => {
Object.assign(activeConfig, defaultConfig)
})
const minifiedConfigs = activeConfigs.reduce(
(minifiedConfigs, activeConfig) => minifiedConfigs.concat(
Object.assign({}, activeConfig, {
plugins: [uglify({}, minify), ...activeConfig.plugins],
dest: activeConfig.dest.replace('js', 'min.js')
})
]
}
),
[]
)
if (minifier === 'on') {
config.plugins.unshift(uglify({}, minify))
config.dest = (format === 'iife')
? 'dist/fetch-inject.min.js'
: `dist/fetch-inject.${format}.min.js`
} else {
config.dest = (format === 'iife')
? 'dist/fetch-inject.js'
: `dist/fetch-inject.${format}.js`
}
export default config
export default activeConfigs.concat(minifiedConfigs)
/**
* ISC License
*
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -6,0 +6,0 @@ * Permission to use, copy, modify, and/or distribute this software for any

/**
* Copyright (c) 2017, Josh Habdas
* Copyright (c) 2017, Josh Habdas <josh@habd.as>
*

@@ -4,0 +4,0 @@ * Permission to use, copy, modify, and/or distribute this software for any

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc